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