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