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