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