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