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