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