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