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