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