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