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