]> git.rmz.io Git - dotfiles.git/blob - vim/vimrc
awesome: move net_widgets to widgets/
[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 Plugin 'vim-scripts/yankring.vim'
54
55 " remove entries first
56 set runtimepath -=$HOME/.vim
57 set runtimepath -=$HOME/.vim/after
58 set runtimepath -=$XDG_CONFIG_HOME/vim
59 set runtimepath -=$XDG_CONFIG_HOME/vim/after
60 " then prepend and append them
61 set runtimepath ^=$XDG_CONFIG_HOME/vim
62 set runtimepath +=$XDG_CONFIG_HOME/vim/after
63
64 filetype plugin indent on
65
66 " colorscheme {{{1
67 syntax on
68 colorscheme badwolf
69
70 " options {{{1
71 " moving around, searching and patterns {{{2
72 set incsearch " show match for partly typed search command
73 set ignorecase " ignore case when using a search pattern
74 set smartcase " override 'ignorecase' when pattern has upper case characters
75 set hlsearch " highlight all matches for the last used search pattern
76
77 set nostartofline " don't move the cursor to the first non-blank char of a line
78 set path=.,include/,../include/,/usr/include/c++/*,/opt/ros/hydro/include
79
80 " displaying text {{{2
81 set scrolloff=5 " number of screen lines to show around the cursor
82 set nowrap " long lines wrap
83 set linebreak " wrap long lines at a character in 'breakat'
84 set showbreak=↪ " show these chars for wrapped lines
85
86 set lazyredraw " don't redraw while executing macros
87
88 set list " show chars defined in 'listchars'
89 set listchars=tab:▸\ " list of strings used for list mode
90 set listchars+=extends:❯,precedes:❮
91 " Only shown when not in insert mode
92 augroup trailing
93 au!
94 au InsertEnter * :set listchars-=trail:·
95 au InsertLeave * :set listchars+=trail:·
96 augroup END
97
98 set sidescroll=1 " number of collumns to scroll
99 set sidescrolloff=1 " don't scroll over the listchars
100
101 set fillchars=diff:⣿,vert:│
102
103 set nonumber " show the line number for each line
104 set norelativenumber " show the relative line number for each line
105
106 " syntax, highlighting and spelling {{{2
107 set synmaxcol=800 " don't highlight long lines
108
109 set dictionary=spell " list of dictionary files for keyword completion
110
111 set colorcolumn=+1
112
113 " multiple windows {{{2
114 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
115
116 set previewheight=20 " default height for the preview window
117
118 set hidden
119
120 " set splitbelow " a new window is put below of the current one
121 set splitright " a new window is put right of the current one
122
123 " terminal {{{2
124 set ttyfast
125
126 " using the mouse {{{2
127 set mouse=rnv " list of flags for using the mouse
128 set ttymouse=xterm " type of mouse
129
130 " messages and info {{{2
131 set showcmd " Show (partial) command in status line.
132 set ruler " show the cursor position all the time
133 set confirm " Ask what to do when closing unsaved documents
134 set shortmess=filnxtoOI " don't show intro message
135
136 " editing text {{{2
137 set backspace=indent,eol,start " allow backspacing over everything in insert mode
138
139 set showmatch " Show matching brackets.
140
141 set nojoinspaces " don't use two spaces after '.' when joining a line
142 set formatoptions=jcrnql
143
144 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
145
146 set complete=.,w,b,u,t
147 " whether to use a popup menu for Insert mode completion
148 set completeopt=longest,menuone,preview
149
150 " tabs and indent {{{2
151 set shiftwidth=4 " number of spaces used for each step of (auto)indent
152 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
153 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
154 set shiftround " round to 'shiftwidth' for "<<" and ">>"
155 set expandtab " expand <Tab> to spaces in Insert mode
156 set autoindent
157
158 set pastetoggle=<F11> " key sequence to toggle paste mode
159
160 " folding {{{2
161 set foldmethod=marker " folding type
162 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
163
164 " save and restore folds
165 set viewoptions=folds,cursor " don't save local options
166
167 " diff mode {{{2
168 set diffopt=filler,vertical
169
170 " reading and writing files {{{2
171 set modeline " read modelines
172 set modelines=2 " only check first/last 2 lines
173
174 set writebackup " write a backup file before overwriting a file
175 set backup " keep a backup after owerwriting a file
176 set backupdir=$XDG_CACHE_HOME/vim/backup//
177
178 set backupskip+=.netrc " skip netrc
179 set backupskip+=/dev/shm/pass* " skip passwordstore files
180
181 set undofile " persistent undo history
182 set undodir=$XDG_CACHE_HOME/vim/undo//
183
184 augroup undoskip
185 au!
186 au BufWritePre .netrc setlocal noundofile
187 au BufWritePre /dev/shm/pass* setlocal noundofile
188 au BufWritePre /tmp/* setlocal noundofile
189 augroup END
190
191 set autowrite " automatically write a file when leaving a modified buffer
192 set autoread " automatically read a file that has been modified
193
194 " the swap file {{{2
195 set noswapfile
196 set directory=$XDG_CACHE_HOME/vim/swap//
197
198 " command line editing {{{2
199 set history=5000 " how many command lines are remembered
200 set wildmenu " command-line completion shows a list of matches
201 set wildmode=longest:full,full " specifies how command line completion works
202
203 set wildignore+=.hg,.git,.svn " Version control
204 set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
205 set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
206 set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
207 set wildignore+=*.spl " compiled spelling word lists
208 set wildignore+=*.sw? " Vim swap files
209 set wildignore+=*.luac " Lua byte code
210 set wildignore+=*.pyc " Python byte code
211 set wildignore+=*.orig " Merge resolution files
212
213 " various {{{2
214 set virtualedit=block " let cursor move past last char in <C-V> mode
215 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
216
217 set viewdir=$XDG_CACHE_HOME/vim/view//
218
219 " autocmds {{{1
220 " Resize splits when the window is resized {{{2
221 augroup resize
222 au!
223 autocmd VimResized * :wincmd =
224 augroup END
225
226 " Only show cursorline in the current window and in normal mode {{{2
227 augroup cline
228 au!
229 au WinLeave,InsertEnter * set nocursorline
230 au WinEnter,InsertLeave * set cursorline
231 augroup END
232
233 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
234 augroup ft_stdin
235 au!
236 au StdinReadPost * :set buftype=nofile
237 augroup END
238
239 " Jump to last known cursor position {{{2
240 augroup cursor_pos
241 au!
242 " blacklist certain filetype
243 let blacklist = ['gitcommit']
244 autocmd BufReadPost *
245 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
246 \ exe "normal! g`\"" |
247 \ endif
248 augroup END
249
250 " bindings {{{1
251
252 " allow both <space> and / to be <leader>
253 map <space> <leader>
254
255 " make
256 nnoremap <leader><cr> :make<cr>
257
258 " unhighlight search
259 nnoremap <silent> <Leader>/ :silent nohl<CR>
260
261 " Tabs
262 nnoremap <leader>[ :tabprev<cr>
263 nnoremap <leader>] :tabnext<cr>
264
265 " Wrap
266 nnoremap <leader>W :set wrap!<cr>
267
268 " paste from selection
269 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
270 " paste from clipboard
271 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
272
273 " Clean trailing whitespace
274 nnoremap <silent> <leader>ww m':%s/\s\+$//<cr>:let @/=''<cr>``zz
275
276 " Source
277 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
278 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
279
280 " jump to last cursor position
281 noremap ' `
282
283 " Select (charwise) the contents of the current line, excluding indentation.
284 nnoremap vv ^vg_
285
286 " Toggle [i]nvisible characters
287 nnoremap <leader>i :set list!<cr>
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 " allow undoing in insert-mode
376 inoremap <C-U> <C-G>u<C-U>
377 inoremap <C-W> <C-G>u<C-W>
378
379 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
380 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
381 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
382 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
383
384 " space will toggle current fold in normal mode
385 nnoremap <leader><Space> za
386 " create folds around visual selection
387 vnoremap <leader><Space> zf
388
389 autocmd BufWinLeave *.* mkview
390 autocmd BufWinEnter *.* silent loadview
391
392 " save with sudo
393 cnoremap w!! w !sudo tee % > /dev/null
394
395 " plugins {{{1
396 " ag {{{2
397 let g:AgSmartCase = 1
398 nnoremap <leader>ag yiw:Ag \12"<cr>
399 vnoremap <leader>ag y:Ag \12"<cr>
400
401 " airline {{{2
402 let g:airline_detect_whitespace=2
403 let g:airline#extensions#tabline#enabled = 1
404 let g:airline_powerline_fonts = 1
405
406 " checkattach {{{2
407 let g:checkattach_filebrowser = 'ranger'
408
409 " delimitmate {{{2
410 let delimitMate_expand_cr = 2
411 let g:delimitMate_expand_space = 1
412
413 " fswitch {{{2
414 nnoremap <silent> <Leader>ff :FSHere<CR>
415 nnoremap <silent> <Leader>fl :FSRight<CR>
416 nnoremap <silent> <Leader>fh :FSLeft<CR>
417 nnoremap <silent> <Leader>fL :FSSplitRight<CR>
418 nnoremap <silent> <Leader>fH :FSSplitLeft<CR>
419
420 " fugitive {{{2
421 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
422 " delete fugitive buffers when closed
423 autocmd BufReadPost fugitive://* set bufhidden=delete
424
425 nnoremap <silent> <leader>gs :Gstatus<CR>
426 nnoremap <silent> <leader>gd :Gdiff<CR>
427 nnoremap <silent> <leader>gc :tab Gcommit -v<CR>
428 nnoremap <silent> <leader>ga :Gwrite<cr>
429 nnoremap <silent> <leader>gb :Gblame<cr>
430
431 " Gundo {{{2
432 nnoremap <F7> :GundoToggle<CR>
433
434 " indent-guides {{{2
435 let g:indent_guides_default_mapping = 0
436 let g:indent_guides_guide_size = 1
437 nmap <silent> cog <Plug>IndentGuidesToggle
438 nmap <silent> [og <Plug>IndentGuidesEnable
439 nmap <silent> ]og <Plug>IndentGuidesDisable
440
441 " NERDTree {{{2
442 " open/close NERDTree with \e
443 nmap <Leader>e :NERDTreeToggle<CR>
444 nmap <F6> :NERDTreeToggle<CR>
445 " <space> to open files/dirs
446 let NERDTreeMapActivateNode='l'
447 " close vim if only NERDTree is open
448 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
449
450 " python-mode {{{2
451
452 let g:pymode_rope_completion = 0
453 let g:pymode_rope = 0
454 let g:pymode_folding = 1
455 let g:pymode_lint_ignore = "E221,E266,E501"
456 let g:pymode_syntax_space_errors = 0 " don't bother me when I'm typing
457
458 " synastic {{{2
459 let g:syntastic_enable_highlighting = 0
460 let g:syntastic_error_symbol='E'
461 let g:syntastic_style_error_symbol='S'
462 let g:syntastic_warning_symbol='W'
463 let g:syntastic_style_warning_symbol='S'
464 let g:syntastic_always_populate_loc_list=1
465 nmap <silent> <leader>y :SyntasticCheck<cr>
466
467 if ! &diff
468 let g:syntastic_check_on_open=1
469 endif
470
471 " tagbar {{{2
472 map <F5> :TagbarToggle<cr>
473 let g:tagbar_sort = 0
474 let g:tagbar_compact = 1
475 let g:tagbar_autoshowtag = 1
476 let g:tagbar_width = 25
477 let g:tagbar_iconchars = ['+', '-']
478
479 " UltiSnips {{{2
480 let g:UltiSnipsEditSplit = 'vertical'
481 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
482 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
483 let g:UltiSnipsExpandTrigger = "<C-L>"
484 let g:UltiSnipsJumpForwardTrigger = "<C-L>"
485 let g:UltiSnipsJumpBackwardTrigger = "<C-H>"
486
487 " yankring {{{2
488 nnoremap <silent> <leader>p :YRShow<cr>
489 let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
490 let g:yankring_replace_n_pkey = ''
491 let g:yankring_replace_n_nkey = ''
492
493 " map Y to y$ for the yank ring
494 function! YRRunAfterMaps()
495 nnoremap Y :<C-U>YRYankCount 'y$'<CR>
496 endfunction
497
498 " youcompleteme {{{2
499 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
500 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
501 let g:ycm_extra_conf_vim_data = ['getcwd()']
502 let g:ycm_add_preview_to_completeopt = 1
503 let g:ycm_autoclose_preview_window_after_insertion = 1
504 "let g:ycm_extra_conf_vim_data = ['%:p']
505 nnoremap <leader>jd :YcmCompleter GoTo<CR>
506
507 " vim-easy-align {{{2
508 " start interactive EasyAlign in visual mode
509 vmap <Enter> <Plug>(EasyAlign)
510
511 " vim-json {{{2
512 let g:vim_json_syntax_conceal = 0
513
514 " vim-latex {{{2
515 let g:tex_flavor='latex'
516 let g:Tex_DefaultTargetFormat='pdf'
517 let g:Tex_MultipleCompileFormats='pdf'
518
519
520 " functions {{{1
521
522 " Convenient command to see the difference between the current buffer and the
523 " file it was loaded from, thus the changes you made.
524 " Only define it when not defined already.
525 if !exists(":DiffOrig")
526 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
527 \ | wincmd p | diffthis
528 endif
529
530 " spell check {{{2
531 " http://tex.stackexchange.com/a/52932
532 let g:myLangList=["en_gb","en_us","de","fr"]
533
534 function! ToggleSpell()
535 if !exists("b:myLang")
536 let b:myLang=0
537 endif
538 execute "setlocal spell!"
539 if (&spell)
540 echo "setlocal spelllang=" g:myLangList[b:myLang]
541 endif
542 endfunction
543
544 function! SwitchSpell()
545 if !exists("b:myLang")
546 let b:myLang=0
547 endif
548 if (&spell)
549 let b:myLang=b:myLang+1
550 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
551 endif
552 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
553 echo "setlocal spelllang=" g:myLangList[b:myLang]
554 endfunction
555
556 nnoremap <silent> <Leader>s :call ToggleSpell()<CR>
557 nnoremap <silent> <Leader>S :call SwitchSpell()<CR>
558 " fix spelling with first choice
559 nnoremap <Leader>f 1z=