]> git.rmz.io Git - dotfiles.git/blob - vim/vimrc
vim: remove <C-U> mapping (disabled by ycm anyway)
[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#rc('$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 'kien/ctrlp.vim'
24 Plugin 'klen/python-mode'
25 Plugin 'kshenoy/vim-signature'
26 Plugin 'majutsushi/tagbar'
27 Plugin 'raimondi/delimitmate'
28 Plugin 'rking/ag.vim'
29 Plugin 'scrooloose/nerdtree'
30 Plugin 'scrooloose/syntastic'
31 Plugin 'sjl/gundo.vim'
32 Plugin 'tomtom/tcomment_vim'
33 Plugin 'tpope/vim-endwise'
34 Plugin 'tpope/vim-fugitive'
35 Plugin 'tpope/vim-repeat'
36 Plugin 'tpope/vim-surround'
37 Plugin 'tpope/vim-unimpaired'
38 Plugin 'valloric/youcompleteme'
39 Plugin 'vim-scripts/yankring.vim'
40
41 " snippets
42 Plugin 'sirver/ultisnips'
43 Plugin 'honza/vim-snippets'
44
45 " ros
46 Plugin 'ompugao/ros.vim'
47 Plugin 'ompugao/ctrlp-ros'
48
49 " seems to have problems right now... may be add later?
50 " Plugin 'jalcine/cmake.vim'
51 " Plugin 'powerman/vim-plugin-viewdoc'
52
53 " find an alternative
54 Plugin 'http://git.code.sf.net/p/vim-latex/vim-latex'
55 " Plugin 'lokaltog/vim-easymotion'
56 Plugin 'justinmk/vim-sneak'
57 Plugin 'chrisbra/checkattach'
58 Plugin 'nathanaelkane/vim-indent-guides'
59
60 " remove entries first
61 set runtimepath -=$HOME/.vim
62 set runtimepath -=$HOME/.vim/after
63 set runtimepath -=$XDG_CONFIG_HOME/vim
64 set runtimepath -=$XDG_CONFIG_HOME/vim/after
65 " then prepend and append them
66 set runtimepath ^=$XDG_CONFIG_HOME/vim
67 set runtimepath +=$XDG_CONFIG_HOME/vim/after
68
69 filetype plugin indent on
70
71 " colorscheme {{{1
72 syntax on
73 colorscheme badwolf
74
75 " options {{{1
76 " moving around, searching and patterns {{{2
77 set incsearch " show match for partly typed search command
78 set ignorecase " ignore case when using a search pattern
79 set smartcase " override 'ignorecase' when pattern has upper case characters
80 set hlsearch " highlight all matches for the last used search pattern
81
82 set nostartofline " don't move the cursor to the first non-blank char of a line
83 set path=.,include/,../include/,/usr/include/c++/*,/opt/ros/hydro/include
84
85 " displaying text {{{2
86 set scrolloff=5 " number of screen lines to show around the cursor
87 set nowrap " long lines wrap
88 set linebreak " wrap long lines at a character in 'breakat'
89 set showbreak=↪ " show these chars for wrapped lines
90
91 set lazyredraw " don't redraw while executing macros
92
93 set list " show chars defined in 'listchars'
94 set listchars=tab:▸\ " list of strings used for list mode
95 set listchars+=extends:❯,precedes:❮
96 " Only shown when not in insert mode
97 augroup trailing
98 au!
99 au InsertEnter * :set listchars-=trail:·
100 au InsertLeave * :set listchars+=trail:·
101 augroup END
102
103 set sidescroll=1 " number of collumns to scroll
104 set sidescrolloff=1 " don't scroll over the listchars
105
106 set fillchars=diff:⣿,vert:│
107
108 set nonumber " show the line number for each line
109 set norelativenumber " show the relative line number for each line
110
111 " syntax, highlighting and spelling {{{2
112 set synmaxcol=800 " don't highlight long lines
113
114 set dictionary=spell " list of dictionary files for keyword completion
115
116 set colorcolumn=+1
117
118 " multiple windows {{{2
119 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
120
121 set previewheight=20 " default height for the preview window
122
123 set hidden
124
125 " set splitbelow " a new window is put below of the current one
126 set splitright " a new window is put right of the current one
127
128 " terminal {{{2
129 set ttyfast
130
131 " using the mouse {{{2
132 set mouse=rnv " list of flags for using the mouse
133 set ttymouse=xterm " type of mouse
134
135 " messages and info {{{2
136 set showcmd " Show (partial) command in status line.
137 set ruler " show the cursor position all the time
138 set confirm " Ask what to do when closing unsaved documents
139 set shortmess=filnxtoOI " don't show intro message
140
141 " editing text {{{2
142 set backspace=indent,eol,start " allow backspacing over everything in insert mode
143
144 set showmatch " Show matching brackets.
145
146 set nojoinspaces " don't use two spaces after '.' when joining a line
147 set formatoptions=jcrnql
148
149 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
150
151 set complete=.,w,b,u,t
152 " whether to use a popup menu for Insert mode completion
153 set completeopt=longest,menuone,preview
154
155 " tabs and indent {{{2
156 set shiftwidth=4 " number of spaces used for each step of (auto)indent
157 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
158 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
159 set shiftround " round to 'shiftwidth' for "<<" and ">>"
160 set expandtab " expand <Tab> to spaces in Insert mode
161 set autoindent
162
163 set pastetoggle=<F11> " key sequence to toggle paste mode
164
165 " folding {{{2
166 set foldmethod=marker " folding type
167 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
168
169 " save and restore folds
170 set viewoptions=folds,cursor " don't save local options
171
172 " diff mode {{{2
173 set diffopt=filler,vertical
174
175 " reading and writing files {{{2
176 set modeline " read modelines
177 set modelines=2 " only check first/last 2 lines
178
179 set writebackup " write a backup file before overwriting a file
180 set backup " keep a backup after owerwriting a file
181 set backupdir=$XDG_CACHE_HOME/vim/backup//
182
183 set backupskip+=.netrc " skip netrc
184 set backupskip+=/dev/shm/pass* " skip passwordstore files
185
186 set undofile " persistent undo history
187 set undodir=$XDG_CACHE_HOME/vim/undo//
188
189 augroup undoskip
190 au!
191 au BufWritePre .netrc setlocal noundofile
192 au BufWritePre /dev/shm/pass* setlocal noundofile
193 au BufWritePre /tmp/* setlocal noundofile
194 augroup END
195
196 set autowrite " automatically write a file when leaving a modified buffer
197 set autoread " automatically read a file that has been modified
198
199 " the swap file {{{2
200 set noswapfile
201 set directory=$XDG_CACHE_HOME/vim/swap//
202
203 " command line editing {{{2
204 set history=5000 " how many command lines are remembered
205 set wildmenu " command-line completion shows a list of matches
206 set wildmode=longest:full,full " specifies how command line completion works
207
208 set wildignore+=.hg,.git,.svn " Version control
209 set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
210 set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
211 set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
212 set wildignore+=*.spl " compiled spelling word lists
213 set wildignore+=*.sw? " Vim swap files
214 set wildignore+=*.luac " Lua byte code
215 set wildignore+=*.pyc " Python byte code
216 set wildignore+=*.orig " Merge resolution files
217
218 " various {{{2
219 set virtualedit=block " let cursor move past last char in <C-V> mode
220 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
221
222 set viewdir=$XDG_CACHE_HOME/vim/view//
223
224 " autocmds {{{1
225 " Resize splits when the window is resized {{{2
226 augroup resize
227 au!
228 autocmd VimResized * :wincmd =
229 augroup END
230
231 " Only show cursorline in the current window and in normal mode {{{2
232 augroup cline
233 au!
234 au WinLeave,InsertEnter * set nocursorline
235 au WinEnter,InsertLeave * set cursorline
236 augroup END
237
238 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
239 augroup ft_stdin
240 au!
241 au StdinReadPost * :set buftype=nofile
242 augroup END
243
244 " Jump to last known cursor position {{{2
245 augroup cursor_pos
246 au!
247 " blacklist certain filetype
248 let blacklist = ['gitcommit']
249 autocmd BufReadPost *
250 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
251 \ exe "normal! g`\"" |
252 \ endif
253 augroup END
254
255 " bindings {{{1
256
257 " allow both <space> and / to be <leader>
258 map <space> <leader>
259
260 " make
261 nnoremap <leader>r :make<cr>
262 nnoremap <leader><cr> :make<cr>
263
264 " unhighlight search
265 nnoremap <silent> <Leader>/ :silent nohl<CR>
266
267 " Tabs
268 nnoremap <leader>[ :tabprev<cr>
269 nnoremap <leader>] :tabnext<cr>
270
271 " paste from selection
272 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
273 " paste from clipboard
274 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
275
276 " Clean trailing whitespace
277 nnoremap <silent> <leader>ww m':%s/\s\+$//<cr>:let @/=''<cr>``zz
278
279 " Source
280 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
281 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
282
283 " jump to last cursor position
284 noremap ' `
285
286 " Select (charwise) the contents of the current line, excluding indentation.
287 nnoremap vv ^vg_
288
289 " Unfuck my screen
290 nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
291
292 " Ranger
293 " nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
294 " nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
295
296 " Use sane regexes.
297 nnoremap / /\v
298 vnoremap / /\v
299 cnoremap s/ s/\v
300
301 " display the number of matches for the last search
302 nmap <Leader># :%s:<C-R>/::gn<CR>
303
304 " center cursor after search and open folds
305 nnoremap n nzzzv
306 nnoremap N Nzzzv
307
308 " same when jumping around
309 nnoremap g; g;zzzv
310 nnoremap g, g,zzzv
311 nnoremap <c-o> <c-o>zzzv
312
313 " Not using the default mappings of 'To line from top/bottom'
314 noremap H ^
315 noremap L $
316 vnoremap H ^
317 vnoremap L g_
318
319 " Heresy, emacs insert bindings
320 inoremap <c-a> <esc>I
321 inoremap <c-e> <esc>A
322 cnoremap <c-a> <home>
323 cnoremap <c-e> <end>
324
325 " proper movement when lines are wrapped
326 noremap <expr> j (v:count == 0 ? 'gj' : 'j')
327 noremap <expr> k (v:count == 0 ? 'gk' : 'k')
328
329 " disable arrows
330 noremap <Up> <NOP>
331 noremap <Down> <NOP>
332 noremap <Left> <NOP>
333 noremap <Right> <NOP>
334 inoremap <Up> <NOP>
335 inoremap <Down> <NOP>
336 inoremap <Left> <NOP>
337 inoremap <Right> <NOP>
338 cnoremap <Up> <NOP>
339 cnoremap <Down> <NOP>
340 cnoremap <Left> <NOP>
341 cnoremap <Right> <NOP>
342 cnoremap <C-K> <Up>
343 cnoremap <C-J> <Down>
344 cnoremap <C-H> <Left>
345 cnoremap <C-L> <Right>
346
347 " close all folds open fold in cursor
348 nnoremap zx zMzxzt
349
350 " edit vimrc in new tab
351 nmap <leader>ev :tabedit $MYVIMRC<CR>:lcd %:p:h<CR>
352
353 map <F1> :ls<CR>:b<space>
354
355 nnoremap <C-L> <C-W>w
356 nnoremap <C-H> <C-W>W
357
358 "xterm mouse with middleclick paste
359 nnoremap <MiddleMouse> i<MiddleMouse>
360 vnoremap <MiddleMouse> s<MiddleMouse>
361
362 " fix legacy vi inconsistency
363 map Y y$
364
365 " allow repeat operator on visual
366 vnoremap . :normal .<CR>
367
368 " add line without changing position or leaving mode
369 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
370 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
371
372 " Don't use Ex mode, use Q for formatting
373 map Q gq
374
375 " break undo sequence before removing word
376 inoremap <C-W> <C-G>u<C-W>
377
378 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
379 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
380 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
381 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
382
383 " space will toggle current fold in normal mode
384 nnoremap <leader><Space> za
385 " create folds around visual selection
386 vnoremap <leader><Space> zf
387
388 autocmd BufWinLeave *.* mkview
389 autocmd BufWinEnter *.* silent loadview
390
391 " save with sudo
392 cnoremap w!! w !sudo tee % > /dev/null
393
394 " uppercase previous word
395 inoremap <C-C> <Esc>gUiwgi
396
397 " plugins options {{{1
398 " ag {{{2
399 let g:AgSmartCase = 1
400 nnoremap <leader>ag yiw:Ag \12"<cr>
401 vnoremap <leader>ag y:Ag \12"<cr>
402
403 " airline {{{2
404 let g:airline#extensions#whitespace#enabled = 1
405 let g:airline#extensions#tabline#enabled = 1
406 let g:airline_powerline_fonts = 1
407
408 " checkattach {{{2
409 let g:checkattach_filebrowser = 'ranger'
410 let g:checkattach_once = 'y'
411
412 " delimitmate {{{2
413 let delimitMate_expand_cr = 2
414 let g:delimitMate_expand_space = 1
415
416 " fswitch {{{2
417 nnoremap <silent> <Leader>ff :FSHere<CR>
418 nnoremap <silent> <Leader>fl :FSRight<CR>
419 nnoremap <silent> <Leader>fh :FSLeft<CR>
420 nnoremap <silent> <Leader>fL :FSSplitRight<CR>
421 nnoremap <silent> <Leader>fH :FSSplitLeft<CR>
422
423 " fugitive {{{2
424 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
425 " delete fugitive buffers when closed
426 autocmd BufReadPost fugitive://* set bufhidden=delete
427
428 nnoremap <silent> <leader>gs :Gstatus<CR>
429 nnoremap <silent> <leader>gd :Gdiff<CR>
430 nnoremap <silent> <leader>gc :tab Gcommit -v<CR>
431 nnoremap <silent> <leader>ga :Gwrite<cr>
432 nnoremap <silent> <leader>gb :Gblame<cr>
433
434 " Gundo {{{2
435 nnoremap <F7> :GundoToggle<CR>
436
437 " indent-guides {{{2
438 let g:indent_guides_default_mapping = 0
439 let g:indent_guides_guide_size = 1
440 nmap <silent> cog <Plug>IndentGuidesToggle
441 nmap <silent> [og <Plug>IndentGuidesEnable
442 nmap <silent> ]og <Plug>IndentGuidesDisable
443
444 " NERDTree {{{2
445 " open/close NERDTree with \e
446 nmap <Leader>e :NERDTreeToggle<CR>
447 nmap <F6> :NERDTreeToggle<CR>
448 " <space> to open files/dirs
449 let NERDTreeMapActivateNode='l'
450 " close vim if only NERDTree is open
451 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
452
453 " python-mode {{{2
454
455 let g:pymode_rope_completion = 0
456 let g:pymode_rope = 0
457 let g:pymode_folding = 1
458 let g:pymode_lint_ignore = "E221,E266,E501"
459 let g:pymode_syntax_space_errors = 0 " don't bother me when I'm typing
460
461 " synastic {{{2
462 let g:syntastic_enable_highlighting = 0
463 let g:syntastic_error_symbol='E'
464 let g:syntastic_style_error_symbol='S'
465 let g:syntastic_warning_symbol='W'
466 let g:syntastic_style_warning_symbol='S'
467 let g:syntastic_always_populate_loc_list=1
468 nmap <silent> <leader>y :SyntasticCheck<cr>
469
470 if ! &diff
471 let g:syntastic_check_on_open=1
472 endif
473
474 " tagbar {{{2
475 map <F5> :TagbarToggle<cr>
476 let g:tagbar_sort = 0
477 let g:tagbar_compact = 1
478 let g:tagbar_autoshowtag = 1
479 let g:tagbar_width = 25
480 let g:tagbar_iconchars = ['+', '-']
481
482 " UltiSnips {{{2
483 let g:UltiSnipsEditSplit = 'vertical'
484 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
485 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
486 let g:UltiSnipsExpandTrigger = "<tab>"
487 let g:UltiSnipsJumpForwardTrigger = "<tab>"
488 let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
489
490 " UltiSnips completion function that tries to expand a snippet. If there's no
491 " snippet for expanding, it checks for completion window and if it's shown,
492 " selects first element. If there's no completion window it tries to jump to
493 " next placeholder. If there's no placeholder it just returns TAB key
494 " https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-15451411
495 function! g:UltiSnips_Complete()
496 call UltiSnips#ExpandSnippet()
497 if g:ulti_expand_res == 0
498 if pumvisible()
499 return "\<C-n>"
500 else
501 call UltiSnips#JumpForwards()
502 if g:ulti_jump_forwards_res == 0
503 return "\<TAB>"
504 endif
505 endif
506 endif
507 return ""
508 endfunction
509 au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
510 let g:UltiSnipsListSnippets="<c-e>"
511
512 " yankring {{{2
513 nnoremap <silent> <leader>p :YRShow<cr>
514 let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
515 let g:yankring_replace_n_pkey = ''
516 let g:yankring_replace_n_nkey = ''
517
518 " map Y to y$ for the yank ring
519 function! YRRunAfterMaps()
520 nnoremap Y :<C-U>YRYankCount 'y$'<CR>
521 endfunction
522
523 " youcompleteme {{{2
524 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
525 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
526 let g:ycm_extra_conf_vim_data = ['getcwd()']
527 let g:ycm_add_preview_to_completeopt = 1
528 let g:ycm_autoclose_preview_window_after_insertion = 1
529 "let g:ycm_extra_conf_vim_data = ['%:p']
530 nnoremap <leader>jd :YcmCompleter GoTo<CR>
531
532 " vim-easy-align {{{2
533 " start interactive EasyAlign in visual mode
534 vmap <Enter> <Plug>(EasyAlign)
535
536 " vim-json {{{2
537 let g:vim_json_syntax_conceal = 0
538
539 " vim-latex {{{2
540 let g:tex_flavor='latex'
541 let g:Tex_DefaultTargetFormat='pdf'
542 let g:Tex_MultipleCompileFormats='pdf'
543
544 " vim-sneak {{{2
545 let g:sneak#streak = 1
546 let g:sneak#target_labels = "aoeuisnthdpylrcgfqjkxzmwvz" " dvorak
547 let g:sneak#use_ic_scs = 1 " follow 'ignorecase' and 'smartcase'
548
549 " sneaky f and t
550 nmap f <Plug>Sneak_f
551 nmap F <Plug>Sneak_F
552 xmap f <Plug>Sneak_f
553 xmap F <Plug>Sneak_F
554 omap f <Plug>Sneak_f
555 omap F <Plug>Sneak_F
556 nmap t <Plug>Sneak_t
557 nmap T <Plug>Sneak_T
558 xmap t <Plug>Sneak_t
559 xmap T <Plug>Sneak_T
560 omap t <Plug>Sneak_t
561 omap T <Plug>Sneak_T
562
563 " functions {{{1
564
565 " Convenient command to see the difference between the current buffer and the
566 " file it was loaded from, thus the changes you made.
567 " Only define it when not defined already.
568 if !exists(":DiffOrig")
569 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
570 \ | wincmd p | diffthis
571 endif
572
573 " spell check {{{2
574 " http://tex.stackexchange.com/a/52932
575 let g:myLangList=["en_gb","en_us","de","fr"]
576
577 function! ToggleSpell()
578 if !exists("b:myLang")
579 let b:myLang=0
580 endif
581 execute "setlocal spell!"
582 if (&spell)
583 echo "setlocal spelllang=" g:myLangList[b:myLang]
584 endif
585 endfunction
586
587 function! SwitchSpell()
588 if !exists("b:myLang")
589 let b:myLang=0
590 endif
591 if (&spell)
592 let b:myLang=b:myLang+1
593 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
594 endif
595 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
596 echo "setlocal spelllang=" g:myLangList[b:myLang]
597 endfunction
598
599 nnoremap <silent> coS :call SwitchSpell()<CR>
600 " fix spelling with first choice
601 nnoremap <Leader>f 1z=