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