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