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