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