]> git.rmz.io Git - dotfiles.git/blob - vim/vimrc
6192c9f67fd3c9ed8fc5c596563df37a37066061
[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 'vimwiki/vimwiki', { 'branch': 'dev' }
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 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 augroup fugitive_gstatus
540 au!
541 autocmd BufWinEnter */.git/index resize 16
542 augroup end
543
544 " Gundo {{{2
545 nnoremap <F7> :GundoToggle<CR>
546
547 " indent-guides {{{2
548 let g:indent_guides_default_mapping = 0
549 let g:indent_guides_guide_size = 1
550 nmap <silent> cog <Plug>IndentGuidesToggle
551 nmap <silent> [og <Plug>IndentGuidesEnable
552 nmap <silent> ]og <Plug>IndentGuidesDisable
553
554 " close-another-window {{{2
555 nnoremap <silent> <C-W>c <NOP>
556 nnoremap <silent> <C-W>cc <C-W>c
557 nnoremap <silent> <C-W>ch :CloseLeftWindow<CR>
558 nnoremap <silent> <C-W>cl :CloseRightWindow<CR>
559 nnoremap <silent> <C-W>cj :CloseBelowWindow<CR>
560 nnoremap <silent> <C-W>ck :CloseAboveWindow<CR>
561
562 " python-mode {{{2
563
564 let g:pymode_rope_completion = 0
565 let g:pymode_rope = 0
566 let g:pymode_run = 0
567 let g:pymode_folding = 1
568 let g:pymode_lint_ignore = "E221,E266,E501"
569 let g:pymode_lint_cwindow = 0 " don't open cwindow when linting
570 let g:pymode_syntax_space_errors = 0 " don't bother me when I'm typing
571
572 " signature {{{2
573 " disable '[ mappings
574
575 let g:SignatureMap = {
576 \ 'GotoNextLineAlpha' : "",
577 \ 'GotoPrevLineAlpha' : "",
578 \ 'GotoNextSpotAlpha' : "",
579 \ 'GotoPrevSpotAlpha' : "",
580 \ }
581
582 " switch
583 let g:switch_mapping = "<Leader>s"
584
585 " spellrotate
586 nmap <silent> z] <Plug>(SpellRotateForward)
587 nmap <silent> z[ <Plug>(SpellRotateBackward)
588 vmap <silent> z] <Plug>(SpellRotateForwardV)
589 vmap <silent> z[ <Plug>(SpellRotateBackwardV)
590
591 " synastic {{{2
592 let g:syntastic_enable_highlighting = 0
593 let g:syntastic_error_symbol='E'
594 let g:syntastic_style_error_symbol='S'
595 let g:syntastic_warning_symbol='W'
596 let g:syntastic_style_warning_symbol='S'
597 let g:syntastic_always_populate_loc_list=1
598 nmap <silent> <leader>y :SyntasticCheck<cr>
599
600 let g:syntastic_cpp_clang_tidy_post_args = "-p build*"
601
602 if ! &diff
603 let g:syntastic_check_on_open=1
604 endif
605
606 " tagbar {{{2
607 map <F5> :TagbarToggle<cr>
608 let g:tagbar_sort = 0
609 let g:tagbar_compact = 1
610 let g:tagbar_autoshowtag = 1
611 let g:tagbar_width = 25
612 let g:tagbar_iconchars = ['+', '-']
613
614 " tcomments {{{2
615 let g:tcomment_textobject_inlinecomment = 'gic'
616 let g:tcomment#filetype#guess = 0
617
618 " ultisnips {{{2
619 let g:UltiSnipsEditSplit = 'vertical'
620 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
621 if has('fname_case')
622 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
623 endif
624 let g:UltiSnipsExpandTrigger = "<tab>"
625 let g:UltiSnipsJumpForwardTrigger = "<tab>"
626 let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
627
628 " UltiSnips completion function that tries to expand a snippet. If there's no
629 " snippet for expanding, it checks for completion window and if it's shown,
630 " selects first element. If there's no completion window it tries to jump to
631 " next placeholder. If there's no placeholder it just returns TAB key
632 " https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-15451411
633 function! g:UltiSnips_Complete()
634 call UltiSnips#ExpandSnippet()
635 if g:ulti_expand_res == 0
636 if pumvisible()
637 return "\<C-n>"
638 else
639 call UltiSnips#JumpForwards()
640 if g:ulti_jump_forwards_res == 0
641 return "\<TAB>"
642 endif
643 endif
644 endif
645 return ""
646 endfunction
647 au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
648 let g:UltiSnipsListSnippets="<c-e>"
649
650 " unite {{{2
651 call unite#filters#matcher_default#use(['matcher_fuzzy'])
652 call unite#custom#profile('default', 'context', {
653 \ 'winheight': 20,
654 \ 'direction': 'botright'
655 \ })
656
657 nnoremap [unite] <Nop>
658 nmap <leader>u [unite]
659 nnoremap [unite]u :UniteResume<CR>
660 nnoremap <silent> [u :UnitePrevious<CR>
661 nnoremap <silent> ]u :UniteNext<CR>
662
663 " unite-grep {{{3
664 " seems not respected
665 let g:unite_source_grep_max_candidates = 2000
666 if executable('ag')
667 " Use ag in unite grep source.
668 let g:unite_source_grep_command = 'ag'
669 let g:unite_source_grep_default_opts = '--smart-case --vimgrep --ignore ''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
670 let g:unite_source_grep_recursive_opt = ''
671 end
672 nnoremap <silent> [unite]a :<C-u>Unite grep:.::\12\17<CR>
673 nnoremap <silent> [unite]A :<C-u>Unite grep:.:-w:\12\17<CR>
674 command! -nargs=1 Ag Unite grep:.::<args>
675
676 " unite-file_rec {{{3
677 if executable('ag')
678 " Use ag in unite rec source
679 let g:unite_source_rec_async_command = ['ag', '--follow', '--nocolor', '--nogroup', '-g', '']
680 end
681 nnoremap <silent> [unite]f :<C-u>Unite -start-insert file_rec/async<CR>
682 call unite#custom#source('file_rec/async', 'sorters', 'sorter_selecta')
683
684 " unite-buffer {{{3
685 call unite#custom#default_action('buffer', 'open')
686 nnoremap <silent> [unite]b :<C-u>Unite buffer:-<CR>
687
688 " unite-menu {{{3
689 let g:unite_source_menu_menus = {}
690 let g:unite_source_menu_menus.fugitive = { 'description' : 'fugitive menu'}
691 let g:unite_source_menu_menus.fugitive.command_candidates = {
692 \ 'Gstatus <Leader>gs' : 'Gstatus',
693 \ 'Gcommit -v <Leader>gc' : 'Gcommit -v',
694 \ 'Glog' : 'Glog',
695 \}
696
697 nnoremap <silent> <leader>gg :<C-u>Unite menu:fugitive<CR>
698
699 let g:unite_source_history_yank_enable = 1
700 nnoremap <silent> [unite]p :<C-u>Unite history/yank<CR>
701
702 " yankring {{{2
703 nnoremap <silent> <leader>p :YRShow<cr>
704 let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
705 let g:yankring_replace_n_pkey = ''
706 let g:yankring_replace_n_nkey = ''
707
708 " map Y to y$ for the yank ring
709 function! YRRunAfterMaps()
710 nnoremap Y :<C-U>YRYankCount 'y$'<CR>
711 endfunction
712
713 " youcompleteme {{{2
714 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
715 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
716 let g:ycm_extra_conf_vim_data = ['getcwd()']
717 let g:ycm_add_preview_to_completeopt = 1
718 let g:ycm_complete_in_comments = 1
719 let g:ycm_complete_in_strings = 1
720 let g:ycm_autoclose_preview_window_after_insertion = 0
721
722 " vim-easy-align {{{2
723 " start interactive EasyAlign in visual mode
724 vmap <Enter> <Plug>(EasyAlign)
725 nmap ga <Plug>(EasyAlign)
726
727 " vim-gtest {{{2
728 let g:gtest#highlight_failing_tests = 0
729
730 nnoremap <Leader>tt :GTestRun<CR>
731 nnoremap <Leader>ta :GTestCase *<CR>:GTestName *<CR>:GTestRun<CR>
732 nnoremap <Leader>tu :GTestRunUnderCursor<CR>
733
734 " vim-json {{{2
735 let g:vim_json_syntax_conceal = 0
736
737 " vim-latex {{{2
738 let g:tex_flavor='latex'
739 let g:Tex_DefaultTargetFormat='pdf'
740 let g:Tex_MultipleCompileFormats='pdf'
741
742 " vim-sneak {{{2
743 let g:sneak#streak = 1
744 let g:sneak#target_labels = "aoeuisnthdpylrcgfqjkxzmwvz" " dvorak
745 let g:sneak#use_ic_scs = 1 " follow 'ignorecase' and 'smartcase'
746
747 " sneaky f and t
748 nmap f <Plug>Sneak_f
749 nmap F <Plug>Sneak_F
750 xmap f <Plug>Sneak_f
751 xmap F <Plug>Sneak_F
752 omap f <Plug>Sneak_f
753 omap F <Plug>Sneak_F
754 nmap t <Plug>Sneak_t
755 nmap T <Plug>Sneak_T
756 xmap t <Plug>Sneak_t
757 xmap T <Plug>Sneak_T
758 omap t <Plug>Sneak_t
759 omap T <Plug>Sneak_T
760
761 " vimviki {{{2
762 let g:vimwiki_list = [{'path': '$XDG_DATA_HOME/vimwiki'}]
763 let g:vimwiki_auto_chdir = 1
764 augroup myvimwiki
765 au! BufRead $XDG_DATA_HOME/vimwiki/index.wiki !git -C "%:p:h" pull -q
766 au! BufRead,BufNewFile $XDG_DATA_HOME/vimwiki/diary/*.wiki !git -C "%:p:h" pull -q
767 au! BufWritePost $XDG_DATA_HOME/vimwiki/*.wiki exe '!git add "<afile>";git commit -qm"' . strftime("%FT%R") . '";git push -q'
768 augroup END
769
770 " functions {{{1
771
772 " Convenient command to see the difference between the current buffer and the
773 " file it was loaded from, thus the changes you made.
774 " Only define it when not defined already.
775 if !exists(":DiffOrig")
776 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
777 \ | wincmd p | diffthis
778 endif
779
780 " sort operator {{{2
781 function! SortLinesOpFunc(...)
782 '[,']sort
783 endfunction
784 nnoremap <silent> gs :<C-U>set operatorfunc=SortLinesOpFunc<CR>g@
785 vnoremap <silent> gs :sort<cr>
786
787 " edit configs {{{2
788 function! EditConfig(what)
789 let l:dir = split(&runtimepath,',')[0]
790 if a:what == 'vimrc'
791 let l:file = expand($MYVIMRC)
792 elseif ! isdirectory(globpath(l:dir, a:what))
793 echoe a:what." is not valid!"
794 elseif empty(&filetype)
795 echoe 'filetype is empty!'
796 else
797 let l:file = l:dir.'/'.a:what.'/'.&filetype.'.vim'
798 endif
799
800 execute ':vsplit '.file
801 execute ':lcd %:p:h'
802 endf
803 nmap <leader>ev :call EditConfig('vimrc')<CR>
804 nmap <leader>ef :call EditConfig('ftplugin')<CR>
805 nmap <leader>es :call EditConfig('syntax')<CR>
806 nmap <leader>ei :call EditConfig('indent')<CR>
807 nmap <leader>eu :UltiSnipsEdit<CR>:lcd %:p:h<CR>
808
809 " spell check {{{2
810 " http://tex.stackexchange.com/a/52932
811 let g:myLangList=["en_gb","en_us","de","fr"]
812
813 function! ToggleSpell()
814 if !exists("b:myLang")
815 let b:myLang=0
816 endif
817 execute "setlocal spell!"
818 if (&spell)
819 echo "setlocal spelllang=" g:myLangList[b:myLang]
820 endif
821 endfunction
822
823 function! SwitchSpell()
824 if !exists("b:myLang")
825 let b:myLang=0
826 endif
827 if (&spell)
828 let b:myLang=b:myLang+1
829 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
830 endif
831 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
832 echo "setlocal spelllang=" g:myLangList[b:myLang]
833 endfunction
834
835 nnoremap <silent> coS :call SwitchSpell()<CR>
836 " fix spelling with first choice
837 nnoremap <Leader>f 1z=
838
839 " gitdir or home {{{2
840 " from derek wyatt:
841 " http://git.io/v3GAV
842 function! FindGitDirOrHome()
843 let filedir = expand('%:p:h')
844 if isdirectory(filedir)
845 let cmd = 'bash -c "(cd ' . filedir . '; git rev-parse --show-toplevel 2>/dev/null)"'
846 let gitdir = system(cmd)
847 if strlen(gitdir) == 0
848 return '~'
849 else
850 return gitdir[:-2]
851 endif
852 else
853 return '~'
854 endif
855 endfunction
856 command! Cd cd %:h
857 command! Cdr execute('cd ' . FindGitDirOrHome())
858 command! LCd lcd %:h
859 command! LCdr execute('lcd ' . FindGitDirOrHome())
860
861 " vim:set et sw=2 ts=2 tw=78: