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