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