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