]> git.rmz.io Git - dotfiles.git/blob - vim/vimrc
vim: add original cmake indent file
[dotfiles.git] / vim / vimrc
1 " My vimrc.
2 "
3 " Author: Samir Benmendil <samir.benmendil[at]gmail[dot]com>
4 "
5
6 " plugins {{{1
7 filetype off
8 set runtimepath& " reset rtp
9 " remove all autocommands
10 autocmd!
11
12 set runtimepath+=$XDG_DATA_HOME/vim/vundle
13 call vundle#begin('$XDG_DATA_HOME/vim')
14
15 Plugin 'gmarik/vundle'
16
17 Plugin 'airblade/vim-gitgutter'
18 Plugin 'bling/vim-airline'
19 Plugin 'derekwyatt/vim-fswitch'
20 Plugin 'elzr/vim-json'
21 Plugin 'firef0x/pkgbuild.vim'
22 Plugin 'junegunn/vim-easy-align'
23 Plugin 'justinmk/vim-sneak'
24 Plugin 'klen/python-mode'
25 Plugin 'kshenoy/vim-signature'
26 Plugin 'majutsushi/tagbar'
27 Plugin 'octol/vim-cpp-enhanced-highlight'
28 Plugin 'raimondi/delimitmate'
29 Plugin 'scrooloose/syntastic'
30 Plugin 'shougo/unite.vim'
31 Plugin 'shougo/vimproc.vim'
32 Plugin 'sjl/gundo.vim'
33 Plugin 'tomtom/tcomment_vim'
34 Plugin 'tpope/vim-abolish'
35 Plugin 'tpope/vim-endwise'
36 Plugin 'tpope/vim-fugitive'
37 Plugin 'tpope/vim-repeat'
38 Plugin 'tpope/vim-surround'
39 Plugin 'tpope/vim-unimpaired'
40 Plugin 'valloric/youcompleteme'
41 Plugin 'vim-scripts/replacewithregister'
42 Plugin 'vim-scripts/yankring.vim'
43
44 " colorschemes
45 Plugin 'flazz/vim-colorschemes'
46
47 " snippets
48 Plugin 'sirver/ultisnips'
49 Plugin 'honza/vim-snippets'
50
51 " text objects
52 Plugin 'kana/vim-textobj-user'
53 Plugin 'julian/vim-textobj-variable-segment'
54 Plugin 'sgur/vim-textobj-parameter'
55
56 " ros
57 Plugin 'ompugao/ros.vim'
58 Plugin 'ompugao/ctrlp-ros'
59
60 " seems to have problems right now... may be add later?
61 " Plugin 'jalcine/cmake.vim'
62 " Plugin 'powerman/vim-plugin-viewdoc'
63
64 " staging
65 " find an alternative (latex-box? Automatic Latex Plugin?)
66 Plugin 'http://git.code.sf.net/p/vim-latex/vim-latex'
67 " Plugin 'lokaltog/vim-easymotion'
68 Plugin 'chrisbra/checkattach'
69 Plugin 'nathanaelkane/vim-indent-guides'
70 Plugin 'alx741/vinfo'
71 Plugin 'vim-scripts/mediawiki.vim'
72 Plugin 'derekwyatt/vim-protodef'
73 Plugin 'rdnetto/ycm-generator'
74 " needs editing colorscheme
75 " Plugin 'jeaye/color_coded'
76
77 call vundle#end()
78
79 " remove entries first
80 set runtimepath -=$HOME/.vim
81 set runtimepath -=$HOME/.vim/after
82 set runtimepath -=$XDG_CONFIG_HOME/vim
83 set runtimepath -=$XDG_CONFIG_HOME/vim/after
84 " then prepend and append them
85 set runtimepath ^=$XDG_CONFIG_HOME/vim
86 set runtimepath +=$XDG_CONFIG_HOME/vim/after
87
88 filetype plugin indent on
89
90 " colorscheme {{{1
91 syntax on
92 colorscheme badfox
93
94 " options {{{1
95 " moving around, searching and patterns {{{2
96 set incsearch " show match for partly typed search command
97 set ignorecase " ignore case when using a search pattern
98 set smartcase " override 'ignorecase' when pattern has upper case characters
99 set hlsearch " highlight all matches for the last used search pattern
100
101 set nostartofline " don't move the cursor to the first non-blank char of a line
102 set path+=.
103 set path+=include/
104 set path+=../include/
105 set path+=/usr/include/c++/*
106
107 " displaying text {{{2
108 set nowrap " long lines wrap
109 set linebreak " wrap long lines at a character in 'breakat'
110 set showbreak=↪ " show these chars for wrapped lines
111 set breakindent " preserve indentation in wrapped text
112
113 set lazyredraw " don't redraw while executing macros
114
115 set list " show chars defined in 'listchars'
116 set listchars=tab:❭\ " list of strings used for list mode
117 set listchars+=extends:❯,precedes:❮
118 " Only shown when not in insert mode
119 au InsertLeave * :set listchars+=trail:·
120 augroup trailing
121 au!
122 au InsertEnter * :set listchars-=trail:·
123 au InsertLeave * :set listchars+=trail:·
124 augroup END
125
126 set scrolloff=5 " number of screen lines to show around the cursor
127 set sidescroll=1 " number of collumns to scroll
128 set sidescrolloff=1 " don't scroll over the listchars
129
130 set fillchars=diff:⣿,vert:│
131
132 set nonumber " show the line number for each line
133 set norelativenumber " show the relative line number for each line
134
135 " syntax, highlighting and spelling {{{2
136 set synmaxcol=800 " don't highlight long lines
137
138 set dictionary=spell " list of dictionary files for keyword completion
139
140 set colorcolumn=+1
141
142 " multiple windows {{{2
143 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
144
145 set previewheight=20 " default height for the preview window
146
147 set hidden
148
149 " set splitbelow " a new window is put below of the current one
150 set splitright " a new window is put right of the current one
151
152 " terminal {{{2
153 set ttyfast
154
155 " using the mouse {{{2
156 set mouse=rnv " list of flags for using the mouse
157 set ttymouse=xterm " type of mouse
158
159 " messages and info {{{2
160 set showcmd " Show (partial) command in status line.
161 set ruler " show the cursor position all the time
162 set confirm " Ask what to do when closing unsaved documents
163 set shortmess=filnxtoOI " don't show intro message
164
165 " editing text {{{2
166 set backspace=indent,eol,start " allow backspacing over everything in insert mode
167
168 set showmatch " Show matching brackets.
169
170 set nojoinspaces " don't use two spaces after '.' when joining a line
171 set formatoptions+=j " Delete comment leader when joining lines
172 set formatoptions+=c " Autowrap comments using textwidth
173 set formatoptions+=r " Insert comment leader after hitting <Enter>
174 set formatoptions+=n " Recognize numbered lists
175 set formatoptions+=q " Allow formatting of comments with "gq".
176 set formatoptions+=l " do not wrap lines that have been longer when starting insert mode already
177 set formatoptions+=t " Auto-wrap text using textwidth
178 set formatoptions-=o " Do not insert comment leader after hitting o or O in normal mode
179
180 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
181
182 set complete=. " scan the current buffer ( 'wrapscan' is ignored)
183 set complete+=w " scan buffers from other windows
184 set complete+=b " scan other loaded buffers that are in the buffer list
185 set complete+=u " scan the unloaded buffers that are in the buffer list
186 set complete+=t " scan tags
187 set complete+=i " scan current and included files
188 set complete+=kspell " use the currently active spell checking |spell|
189
190 " whether to use a popup menu for Insert mode completion
191 set completeopt=longest,menuone,preview
192
193 " tabs and indent {{{2
194 set shiftwidth=4 " number of spaces used for each step of (auto)indent
195 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
196 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
197 set shiftround " round to 'shiftwidth' for "<<" and ">>"
198 set expandtab " expand <Tab> to spaces in Insert mode
199 set autoindent
200
201 set pastetoggle=<F11> " key sequence to toggle paste mode
202
203 " folding {{{2
204 set foldmethod=marker " folding type
205 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
206
207 " open folds when jumping to line
208 set foldopen+=jump
209
210 " save and restore folds
211 set viewoptions=cursor " only save cursor position
212
213 " diff mode {{{2
214 set diffopt+=filler " show filler lines
215 set diffopt+=vertical " always vertical split
216 set diffopt+=context:10 " 10 lines context between changes
217
218 " reading and writing files {{{2
219 set modeline " read modelines
220 set modelines=2 " only check first/last 2 lines
221
222 set writebackup " write a backup file before overwriting a file
223 set backup " keep a backup after owerwriting a file
224 set backupdir=$XDG_CACHE_HOME/vim/backup//
225
226 set backupskip+=.netrc " skip netrc
227 set backupskip+=/dev/shm/pass* " skip passwordstore files
228
229 set undofile " persistent undo history
230 set undodir=$XDG_CACHE_HOME/vim/undo//
231
232 augroup undoskip
233 au!
234 au BufWritePre .netrc setlocal noundofile
235 au BufWritePre /dev/shm/pass* setlocal noundofile
236 au BufWritePre /tmp/* setlocal noundofile
237 augroup END
238
239 set autowrite " automatically write a file when leaving a modified buffer
240 set autoread " automatically read a file that has been modified
241
242 " the swap file {{{2
243 set noswapfile
244 set directory=$XDG_CACHE_HOME/vim/swap//
245
246 " command line editing {{{2
247 set history=5000 " how many command lines are remembered
248 set wildmenu " command-line completion shows a list of matches
249 set wildmode=longest:full,full " specifies how command line completion works
250 set wildignorecase " ignore case when completing file names
251
252 set wildignore+=.hg,.git,.svn " Version control
253 set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
254 set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
255 set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
256 set wildignore+=*.spl " compiled spelling word lists
257 set wildignore+=*.sw? " Vim swap files
258 set wildignore+=*.luac " Lua byte code
259 set wildignore+=*.pyc " Python byte code
260 set wildignore+=*.orig " Merge resolution files
261
262 " running make and jumping to errors {{{2
263 set makeprg=make\ -w " print changing directories
264
265 set grepprg=ag\ --vimgrep\ $*
266
267 " language specific {{{2
268 set isfname-== " don't treat `=` as being part of filenames
269
270 " various {{{2
271 set virtualedit+=block " let cursor move past last char in <C-V> mode
272 set virtualedit+=onemore " allow the cursor to move just past the end of the line
273 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
274
275 set viewdir=$XDG_CACHE_HOME/vim/view//
276
277 set sessionoptions+=unix,slash " damn windows and it's silly ways
278
279 " autocmds {{{1
280 " Resize splits when the window is resized {{{2
281 augroup resize
282 au!
283 autocmd VimResized * :wincmd =
284 augroup END
285
286 " Only show cursorline in the current window and in normal mode {{{2
287 augroup cline
288 au!
289 au WinLeave,InsertEnter * set nocursorline
290 au WinEnter,InsertLeave * set cursorline
291 augroup END
292
293 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
294 augroup ft_stdin
295 au!
296 au StdinReadPost * :set buftype=nofile
297 augroup END
298
299 " Jump to last known cursor position {{{2
300 augroup cursor_pos
301 au!
302 " blacklist certain filetype
303 let blacklist = ['gitcommit']
304 autocmd BufReadPost *
305 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
306 \ exe "normal! g`\"" |
307 \ endif
308 augroup END
309
310 " Check for file modifications automatically {{{2
311 " (current buffer only)
312 " Use :NoAutoChecktime to disable it (uses b:autochecktime)
313 fun! MyAutoCheckTime()
314 " only check timestamp for normal files
315 if &buftype != '' | return | endif
316 if ! exists('b:autochecktime') || b:autochecktime
317 checktime %
318 let b:autochecktime = 1
319 endif
320 endfun
321 augroup MyAutoChecktime
322 au!
323 au FocusGained,BufEnter,CursorHold,InsertEnter * call MyAutoCheckTime()
324 augroup END
325 command! NoAutoChecktime let b:autochecktime=0
326 command! ToggleAutoChecktime let b:autochecktime=!get(b:, 'autochecktime', 0) | echom "b:autochecktime:" b:autochecktime
327
328 " bindings {{{1
329
330 " allow both <space> and / to be <leader>
331 map <space> <leader>
332
333 " make
334 nnoremap <leader>r :make!<cr>
335 nnoremap <leader><cr> :make!<cr>
336
337 " unhighlight search
338 nnoremap <silent> <Leader>/ :silent nohl<CR>
339
340 " Tabs
341 nnoremap <leader>[ :tabprev<cr>
342 nnoremap <leader>] :tabnext<cr>
343
344 " paste from selection
345 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
346 " paste from clipboard
347 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
348
349 " strip trailing whitespace
350 function! StripWhitespace(line1, line2, ...) " {{{2
351 let s_report = &report
352 let &report=0
353 let pattern = a:0 ? a:1 : '\s\+$'
354 let oldview = winsaveview()
355 exe 'keepjumps keeppatterns '.a:line1.','.a:line2.'substitute/'.pattern.'//e'
356 if oldview != winsaveview()
357 redraw
358 endif
359 call winrestview(oldview)
360 let &report = s_report
361 endfunction " }}}2
362 command! -range=% -nargs=0 -bar Untrail keepjumps call StripWhitespace(<line1>,<line2>)
363 nnoremap <silent> <leader>ww :Untrail<CR>
364
365 " Source
366 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
367 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
368
369 " jump to last cursor position
370 noremap ' `
371
372 " Select (charwise) the contents of the current line, excluding indentation.
373 nnoremap vv ^vg_
374
375 " Unfuck my screen
376 nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
377
378 " Ranger
379 " nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
380 " nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
381
382 " Use sane regexes.
383 nnoremap / /\v
384 vnoremap / /\v
385 cnoremap s/ s/\v
386
387 " display the number of matches for the last search
388 nmap <Leader># :%s:<C-R>/::gn<CR>
389
390 " center cursor after search and open folds
391 nnoremap n nzzzv
392 nnoremap N Nzzzv
393
394 " same when jumping around
395 nnoremap g; g;zzzv
396 nnoremap g, g,zzzv
397 nnoremap <c-o> <c-o>zzzv
398 nnoremap <c-i> <c-i>zzzv
399
400 " Not using the default mappings of 'To line from top/bottom'
401 noremap H ^
402 noremap L $
403 vnoremap H ^
404 vnoremap L g_
405
406 " Heresy, emacs insert bindings
407 inoremap <C-A> <Esc>I
408 inoremap <C-E> <Esc>A
409 cnoremap <C-A> <Home>
410 cnoremap <C-E> <End>
411
412 " proper movement when lines are wrapped
413 noremap <expr> j (v:count == 0 ? 'gj' : 'j')
414 noremap <expr> k (v:count == 0 ? 'gk' : 'k')
415
416 " disable arrows
417 noremap <Up> <NOP>
418 noremap <Down> <NOP>
419 noremap <Left> <NOP>
420 noremap <Right> <NOP>
421 inoremap <Up> <NOP>
422 inoremap <Down> <NOP>
423 inoremap <Left> <NOP>
424 inoremap <Right> <NOP>
425 cnoremap <Up> <NOP>
426 cnoremap <Down> <NOP>
427 cnoremap <Left> <NOP>
428 cnoremap <Right> <NOP>
429 cnoremap <C-K> <Up>
430 cnoremap <C-J> <Down>
431 cnoremap <C-H> <Left>
432 cnoremap <C-L> <Right>
433
434 " close all folds open fold in cursor
435 nnoremap zx zMzxzt
436
437 map <F1> :ls<CR>:b<space>
438
439 " move between windows
440 nnoremap <C-L> <C-W>w
441 nnoremap <C-H> <C-W>W
442
443 "xterm mouse with middleclick paste
444 nnoremap <MiddleMouse> i<MiddleMouse>
445 vnoremap <MiddleMouse> s<MiddleMouse>
446
447 " fix legacy vi inconsistency
448 nnoremap Y y$
449 " copy to clipboard
450 xnoremap Y "+y
451
452 " allow repeat operator on visual
453 vnoremap . :normal .<CR>
454
455 " add line without changing position or leaving mode
456 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
457 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
458
459 " Don't use Ex mode, use Q for formatting
460 map Q gq
461
462 " break undo sequence before removing word
463 inoremap <C-W> <C-G>u<C-W>
464
465 nnoremap coe :set <C-R>=&expandtab ? 'noexpandtab' : 'expandtab'<CR><CR>
466 nnoremap [oe :set expandtab<CR>
467 nnoremap ]oe :set noexpandtab<CR>
468
469 for idt in range(1,8)
470 exe 'nnoremap co'.idt.' :set tabstop='.idt.' shiftwidth='.idt.' softtabstop='.idt.'<CR>'
471 endfor
472
473 " toggle auto format of text
474 nnoremap coa :set <C-R>=&formatoptions =~ "a" ? 'formatoptions-=a' : 'formatoptions+=a'<CR><CR>
475 nnoremap [oa :set formatoptions+=a<CR>
476 nnoremap ]oa :set formatoptions-=a<CR>
477
478 " space will toggle current fold in normal mode
479 nnoremap <leader><Space> za
480 " create folds around visual selection
481 vnoremap <leader><Space> zf
482
483 autocmd BufWinLeave *.* mkview
484 autocmd BufWinEnter *.* silent loadview
485
486 " save with sudo
487 cabbrev w!! w !sudo tee % > /dev/null
488
489 " uppercase previous word
490 inoremap <C-C> <Esc>gUiwgi
491
492 " http://git.io/v3ZeU
493 nmap <silent> <leader>qq :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
494
495 " plugins options {{{1
496 " airline {{{2
497 let g:airline#extensions#whitespace#enabled = 1
498 let g:airline#extensions#tabline#enabled = 1
499 let g:airline_powerline_fonts = 1
500
501 " checkattach {{{2
502 let g:checkattach_filebrowser = 'ranger'
503 let g:checkattach_once = 'y'
504
505 " delimitmate {{{2
506 let delimitMate_expand_cr = 2
507 let g:delimitMate_expand_space = 1
508
509 " fswitch {{{2
510 nnoremap <silent> <Leader>ff :FSHere<CR>
511 nnoremap <silent> <Leader>fl :FSRight<CR>
512 nnoremap <silent> <Leader>fh :FSLeft<CR>
513 nnoremap <silent> <Leader>fj :FSBelow<CR>
514 nnoremap <silent> <Leader>fk :FSAbove<CR>
515 nnoremap <silent> <Leader>fL :FSSplitRight<CR>
516 nnoremap <silent> <Leader>fH :FSSplitLeft<CR>
517 nnoremap <silent> <Leader>fJ :FSSplitBelow<CR>
518 nnoremap <silent> <Leader>fK :FSSplitAbove<CR>
519
520 " fugitive {{{2
521 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
522 " delete fugitive buffers when closed
523 autocmd BufReadPost fugitive://* set bufhidden=delete
524
525 nnoremap <silent> <leader>gs :Gstatus<CR>
526 nnoremap <silent> <leader>gd :Gdiff<CR>
527 nnoremap <silent> <leader>gc :Gcommit -v<CR>
528 nnoremap <silent> <leader>ga :Gwrite<cr>
529 nnoremap <silent> <leader>gb :Gblame<cr>
530
531 " Gundo {{{2
532 nnoremap <F7> :GundoToggle<CR>
533
534 " indent-guides {{{2
535 let g:indent_guides_default_mapping = 0
536 let g:indent_guides_guide_size = 1
537 nmap <silent> cog <Plug>IndentGuidesToggle
538 nmap <silent> [og <Plug>IndentGuidesEnable
539 nmap <silent> ]og <Plug>IndentGuidesDisable
540
541 " close-another-window {{{2
542 nnoremap <silent> <C-W>c <NOP>
543 nnoremap <silent> <C-W>cc <C-W>c
544 nnoremap <silent> <C-W>ch :CloseLeftWindow<CR>
545 nnoremap <silent> <C-W>cl :CloseRightWindow<CR>
546 nnoremap <silent> <C-W>cj :CloseBelowWindow<CR>
547 nnoremap <silent> <C-W>ck :CloseAboveWindow<CR>
548
549 " python-mode {{{2
550
551 let g:pymode_rope_completion = 0
552 let g:pymode_rope = 0
553 let g:pymode_run = 0
554 let g:pymode_folding = 1
555 let g:pymode_lint_ignore = "E221,E266,E501"
556 let g:pymode_lint_cwindow = 0 " don't open cwindow when linting
557 let g:pymode_syntax_space_errors = 0 " don't bother me when I'm typing
558
559 " signature {{{2
560 " disable '[ mappings
561
562 let g:SignatureMap = {
563 \ 'GotoNextLineAlpha' : "",
564 \ 'GotoPrevLineAlpha' : "",
565 \ 'GotoNextSpotAlpha' : "",
566 \ 'GotoPrevSpotAlpha' : "",
567 \ }
568
569 " synastic {{{2
570 let g:syntastic_enable_highlighting = 0
571 let g:syntastic_error_symbol='E'
572 let g:syntastic_style_error_symbol='S'
573 let g:syntastic_warning_symbol='W'
574 let g:syntastic_style_warning_symbol='S'
575 let g:syntastic_always_populate_loc_list=1
576 nmap <silent> <leader>y :SyntasticCheck<cr>
577
578 if ! &diff
579 let g:syntastic_check_on_open=1
580 endif
581
582 " tagbar {{{2
583 map <F5> :TagbarToggle<cr>
584 let g:tagbar_sort = 0
585 let g:tagbar_compact = 1
586 let g:tagbar_autoshowtag = 1
587 let g:tagbar_width = 25
588 let g:tagbar_iconchars = ['+', '-']
589
590 " ultisnips {{{2
591 let g:UltiSnipsEditSplit = 'vertical'
592 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
593 if has('fname_case')
594 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
595 endif
596 let g:UltiSnipsExpandTrigger = "<tab>"
597 let g:UltiSnipsJumpForwardTrigger = "<tab>"
598 let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
599
600 " UltiSnips completion function that tries to expand a snippet. If there's no
601 " snippet for expanding, it checks for completion window and if it's shown,
602 " selects first element. If there's no completion window it tries to jump to
603 " next placeholder. If there's no placeholder it just returns TAB key
604 " https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-15451411
605 function! g:UltiSnips_Complete()
606 call UltiSnips#ExpandSnippet()
607 if g:ulti_expand_res == 0
608 if pumvisible()
609 return "\<C-n>"
610 else
611 call UltiSnips#JumpForwards()
612 if g:ulti_jump_forwards_res == 0
613 return "\<TAB>"
614 endif
615 endif
616 endif
617 return ""
618 endfunction
619 au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
620 let g:UltiSnipsListSnippets="<c-e>"
621
622 " unite {{{2
623 call unite#filters#matcher_default#use(['matcher_fuzzy'])
624 call unite#custom#profile('default', 'context', {
625 \ 'winheight': 20,
626 \ 'direction': 'botright'
627 \ })
628
629 nnoremap [unite] <Nop>
630 nmap <leader>u [unite]
631
632 " unite-grep {{{3
633 " seems not respected
634 let g:unite_source_grep_max_candidates = 2000
635 if executable('ag')
636 " Use ag in unite grep source.
637 let g:unite_source_grep_command = 'ag'
638 let g:unite_source_grep_default_opts = '--smart-case --vimgrep --hidden --ignore ''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
639 let g:unite_source_grep_recursive_opt = ''
640 end
641 nnoremap <silent> [unite]a :<C-u>Unite grep:.::\12\17<CR>
642 command! -nargs=1 Ag Unite grep:.::<args>
643
644 " unite-file_rec {{{3
645 if executable('ag')
646 " Use ag in unite rec source
647 let g:unite_source_rec_async_command = 'ag --follow --nocolor --nogroup --hidden -g ""'
648 end
649 nnoremap <silent> [unite]f :<C-u>Unite -start-insert file_rec/async<CR>
650 call unite#custom#source('file_rec/async', 'sorters', 'sorter_selecta')
651
652 " unite-buffer {{{3
653 call unite#custom#default_action('buffer', 'open')
654 nnoremap <silent> [unite]b :<C-u>Unite buffer:-<CR>
655
656 " unite-menu {{{3
657 let g:unite_source_menu_menus = {}
658 let g:unite_source_menu_menus.fugitive = { 'description' : 'fugitive menu'}
659 let g:unite_source_menu_menus.fugitive.command_candidates = {
660 \ 'Gstatus <Leader>gs' : 'Gstatus',
661 \ 'Gcommit -v <Leader>gc' : 'Gcommit -v',
662 \ 'Glog' : 'Glog',
663 \}
664
665 nnoremap <silent> <leader>gg :<C-u>Unite menu:fugitive<CR>
666
667 let g:unite_source_history_yank_enable = 1
668 nnoremap <silent> [unite]p :<C-u>Unite history/yank<CR>
669
670 " yankring {{{2
671 nnoremap <silent> <leader>p :YRShow<cr>
672 let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
673 let g:yankring_replace_n_pkey = ''
674 let g:yankring_replace_n_nkey = ''
675
676 " map Y to y$ for the yank ring
677 function! YRRunAfterMaps()
678 nnoremap Y :<C-U>YRYankCount 'y$'<CR>
679 endfunction
680
681 " youcompleteme {{{2
682 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
683 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
684 let g:ycm_extra_conf_vim_data = ['getcwd()']
685 let g:ycm_add_preview_to_completeopt = 1
686 let g:ycm_complete_in_comments = 1
687 let g:ycm_complete_in_strings = 1
688 let g:ycm_autoclose_preview_window_after_insertion = 0
689 "let g:ycm_extra_conf_vim_data = ['%:p']
690
691 " vim-easy-align {{{2
692 " start interactive EasyAlign in visual mode
693 vmap <Enter> <Plug>(EasyAlign)
694 nmap ga <Plug>(EasyAlign)
695
696 " vim-json {{{2
697 let g:vim_json_syntax_conceal = 0
698
699 " vim-latex {{{2
700 let g:tex_flavor='latex'
701 let g:Tex_DefaultTargetFormat='pdf'
702 let g:Tex_MultipleCompileFormats='pdf'
703
704 " vim-sneak {{{2
705 let g:sneak#streak = 1
706 let g:sneak#target_labels = "aoeuisnthdpylrcgfqjkxzmwvz" " dvorak
707 let g:sneak#use_ic_scs = 1 " follow 'ignorecase' and 'smartcase'
708
709 " sneaky f and t
710 nmap f <Plug>Sneak_f
711 nmap F <Plug>Sneak_F
712 xmap f <Plug>Sneak_f
713 xmap F <Plug>Sneak_F
714 omap f <Plug>Sneak_f
715 omap F <Plug>Sneak_F
716 nmap t <Plug>Sneak_t
717 nmap T <Plug>Sneak_T
718 xmap t <Plug>Sneak_t
719 xmap T <Plug>Sneak_T
720 omap t <Plug>Sneak_t
721 omap T <Plug>Sneak_T
722
723 " functions {{{1
724
725 " Convenient command to see the difference between the current buffer and the
726 " file it was loaded from, thus the changes you made.
727 " Only define it when not defined already.
728 if !exists(":DiffOrig")
729 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
730 \ | wincmd p | diffthis
731 endif
732
733 " sort operator {{{2
734 function! SortLinesOpFunc(...)
735 '[,']sort
736 endfunction
737 nnoremap <silent> gs :<C-U>set operatorfunc=SortLinesOpFunc<CR>g@
738 vnoremap <silent> gs :sort<cr>
739
740 " edit configs {{{2
741 function! EditConfig(what)
742 let l:dir = split(&runtimepath,',')[0]
743 if a:what == 'vimrc'
744 let l:file = expand($MYVIMRC)
745 elseif ! isdirectory(globpath(l:dir, a:what))
746 echoe a:what." is not valid!"
747 elseif empty(&filetype)
748 echoe 'filetype is empty!'
749 else
750 let l:file = l:dir.'/'.a:what.'/'.&filetype.'.vim'
751 endif
752
753 execute ':vsplit '.file
754 execute ':lcd %:p:h'
755 endf
756 nmap <leader>ev :call EditConfig('vimrc')<CR>
757 nmap <leader>ef :call EditConfig('ftplugin')<CR>
758 nmap <leader>es :call EditConfig('syntax')<CR>
759 nmap <leader>ei :call EditConfig('indent')<CR>
760 nmap <leader>eu :UltiSnipsEdit<CR>:lcd %:p:h<CR>
761
762 " spell check {{{2
763 " http://tex.stackexchange.com/a/52932
764 let g:myLangList=["en_gb","en_us","de","fr"]
765
766 function! ToggleSpell()
767 if !exists("b:myLang")
768 let b:myLang=0
769 endif
770 execute "setlocal spell!"
771 if (&spell)
772 echo "setlocal spelllang=" g:myLangList[b:myLang]
773 endif
774 endfunction
775
776 function! SwitchSpell()
777 if !exists("b:myLang")
778 let b:myLang=0
779 endif
780 if (&spell)
781 let b:myLang=b:myLang+1
782 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
783 endif
784 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
785 echo "setlocal spelllang=" g:myLangList[b:myLang]
786 endfunction
787
788 nnoremap <silent> coS :call SwitchSpell()<CR>
789 " fix spelling with first choice
790 nnoremap <Leader>f 1z=
791
792 " gitdir or home {{{2
793 " from derek wyatt:
794 " http://git.io/v3GAV
795 function! FindGitDirOrHome()
796 let filedir = expand('%:p:h')
797 if isdirectory(filedir)
798 let cmd = 'bash -c "(cd ' . filedir . '; git rev-parse --show-toplevel 2>/dev/null)"'
799 let gitdir = system(cmd)
800 if strlen(gitdir) == 0
801 return '~'
802 else
803 return gitdir[:-2]
804 endif
805 else
806 return '~'
807 endif
808 endfunction
809 command! Cd cd %:h
810 command! Cr execute('cd ' . FindGitDirOrHome())
811 command! LCd lcd %:h
812 command! LCr execute('lcd ' . FindGitDirOrHome())
813
814 " vim:set et sw=2 ts=2 tw=78: