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