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