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