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