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