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