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