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