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