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