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