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