]> git.rmz.io Git - dotfiles.git/blob - vim/vimrc
vim: add close preview mapping
[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 " tcomments {{{2
599 let g:tcommentTextObjectInlineComment = 'gic'
600
601 " ultisnips {{{2
602 let g:UltiSnipsEditSplit = 'vertical'
603 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
604 if has('fname_case')
605 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
606 endif
607 let g:UltiSnipsExpandTrigger = "<tab>"
608 let g:UltiSnipsJumpForwardTrigger = "<tab>"
609 let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
610
611 " UltiSnips completion function that tries to expand a snippet. If there's no
612 " snippet for expanding, it checks for completion window and if it's shown,
613 " selects first element. If there's no completion window it tries to jump to
614 " next placeholder. If there's no placeholder it just returns TAB key
615 " https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-15451411
616 function! g:UltiSnips_Complete()
617 call UltiSnips#ExpandSnippet()
618 if g:ulti_expand_res == 0
619 if pumvisible()
620 return "\<C-n>"
621 else
622 call UltiSnips#JumpForwards()
623 if g:ulti_jump_forwards_res == 0
624 return "\<TAB>"
625 endif
626 endif
627 endif
628 return ""
629 endfunction
630 au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
631 let g:UltiSnipsListSnippets="<c-e>"
632
633 " unite {{{2
634 call unite#filters#matcher_default#use(['matcher_fuzzy'])
635 call unite#custom#profile('default', 'context', {
636 \ 'winheight': 20,
637 \ 'direction': 'botright'
638 \ })
639
640 nnoremap [unite] <Nop>
641 nmap <leader>u [unite]
642 nnoremap [unite]u :UniteResume<CR>
643
644 " unite-grep {{{3
645 " seems not respected
646 let g:unite_source_grep_max_candidates = 2000
647 if executable('ag')
648 " Use ag in unite grep source.
649 let g:unite_source_grep_command = 'ag'
650 let g:unite_source_grep_default_opts = '--smart-case --vimgrep --hidden --ignore ''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
651 let g:unite_source_grep_recursive_opt = ''
652 end
653 nnoremap <silent> [unite]a :<C-u>Unite grep:.::\12\17<CR>
654 command! -nargs=1 Ag Unite grep:.::<args>
655
656 " unite-file_rec {{{3
657 if executable('ag')
658 " Use ag in unite rec source
659 let g:unite_source_rec_async_command = 'ag --follow --nocolor --nogroup --hidden -g ""'
660 end
661 nnoremap <silent> [unite]f :<C-u>Unite -start-insert file_rec/async<CR>
662 call unite#custom#source('file_rec/async', 'sorters', 'sorter_selecta')
663
664 " unite-buffer {{{3
665 call unite#custom#default_action('buffer', 'open')
666 nnoremap <silent> [unite]b :<C-u>Unite buffer:-<CR>
667
668 " unite-menu {{{3
669 let g:unite_source_menu_menus = {}
670 let g:unite_source_menu_menus.fugitive = { 'description' : 'fugitive menu'}
671 let g:unite_source_menu_menus.fugitive.command_candidates = {
672 \ 'Gstatus <Leader>gs' : 'Gstatus',
673 \ 'Gcommit -v <Leader>gc' : 'Gcommit -v',
674 \ 'Glog' : 'Glog',
675 \}
676
677 nnoremap <silent> <leader>gg :<C-u>Unite menu:fugitive<CR>
678
679 let g:unite_source_history_yank_enable = 1
680 nnoremap <silent> [unite]p :<C-u>Unite history/yank<CR>
681
682 " yankring {{{2
683 nnoremap <silent> <leader>p :YRShow<cr>
684 let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
685 let g:yankring_replace_n_pkey = ''
686 let g:yankring_replace_n_nkey = ''
687
688 " map Y to y$ for the yank ring
689 function! YRRunAfterMaps()
690 nnoremap Y :<C-U>YRYankCount 'y$'<CR>
691 endfunction
692
693 " youcompleteme {{{2
694 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
695 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
696 let g:ycm_extra_conf_vim_data = ['getcwd()']
697 let g:ycm_add_preview_to_completeopt = 1
698 let g:ycm_complete_in_comments = 1
699 let g:ycm_complete_in_strings = 1
700 let g:ycm_autoclose_preview_window_after_insertion = 0
701 "let g:ycm_extra_conf_vim_data = ['%:p']
702
703 " vim-easy-align {{{2
704 " start interactive EasyAlign in visual mode
705 vmap <Enter> <Plug>(EasyAlign)
706 nmap ga <Plug>(EasyAlign)
707
708 " vim-json {{{2
709 let g:vim_json_syntax_conceal = 0
710
711 " vim-latex {{{2
712 let g:tex_flavor='latex'
713 let g:Tex_DefaultTargetFormat='pdf'
714 let g:Tex_MultipleCompileFormats='pdf'
715
716 " vim-sneak {{{2
717 let g:sneak#streak = 1
718 let g:sneak#target_labels = "aoeuisnthdpylrcgfqjkxzmwvz" " dvorak
719 let g:sneak#use_ic_scs = 1 " follow 'ignorecase' and 'smartcase'
720
721 " sneaky f and t
722 nmap f <Plug>Sneak_f
723 nmap F <Plug>Sneak_F
724 xmap f <Plug>Sneak_f
725 xmap F <Plug>Sneak_F
726 omap f <Plug>Sneak_f
727 omap F <Plug>Sneak_F
728 nmap t <Plug>Sneak_t
729 nmap T <Plug>Sneak_T
730 xmap t <Plug>Sneak_t
731 xmap T <Plug>Sneak_T
732 omap t <Plug>Sneak_t
733 omap T <Plug>Sneak_T
734
735 " functions {{{1
736
737 " Convenient command to see the difference between the current buffer and the
738 " file it was loaded from, thus the changes you made.
739 " Only define it when not defined already.
740 if !exists(":DiffOrig")
741 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
742 \ | wincmd p | diffthis
743 endif
744
745 " sort operator {{{2
746 function! SortLinesOpFunc(...)
747 '[,']sort
748 endfunction
749 nnoremap <silent> gs :<C-U>set operatorfunc=SortLinesOpFunc<CR>g@
750 vnoremap <silent> gs :sort<cr>
751
752 " edit configs {{{2
753 function! EditConfig(what)
754 let l:dir = split(&runtimepath,',')[0]
755 if a:what == 'vimrc'
756 let l:file = expand($MYVIMRC)
757 elseif ! isdirectory(globpath(l:dir, a:what))
758 echoe a:what." is not valid!"
759 elseif empty(&filetype)
760 echoe 'filetype is empty!'
761 else
762 let l:file = l:dir.'/'.a:what.'/'.&filetype.'.vim'
763 endif
764
765 execute ':vsplit '.file
766 execute ':lcd %:p:h'
767 endf
768 nmap <leader>ev :call EditConfig('vimrc')<CR>
769 nmap <leader>ef :call EditConfig('ftplugin')<CR>
770 nmap <leader>es :call EditConfig('syntax')<CR>
771 nmap <leader>ei :call EditConfig('indent')<CR>
772 nmap <leader>eu :UltiSnipsEdit<CR>:lcd %:p:h<CR>
773
774 " spell check {{{2
775 " http://tex.stackexchange.com/a/52932
776 let g:myLangList=["en_gb","en_us","de","fr"]
777
778 function! ToggleSpell()
779 if !exists("b:myLang")
780 let b:myLang=0
781 endif
782 execute "setlocal spell!"
783 if (&spell)
784 echo "setlocal spelllang=" g:myLangList[b:myLang]
785 endif
786 endfunction
787
788 function! SwitchSpell()
789 if !exists("b:myLang")
790 let b:myLang=0
791 endif
792 if (&spell)
793 let b:myLang=b:myLang+1
794 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
795 endif
796 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
797 echo "setlocal spelllang=" g:myLangList[b:myLang]
798 endfunction
799
800 nnoremap <silent> coS :call SwitchSpell()<CR>
801 " fix spelling with first choice
802 nnoremap <Leader>f 1z=
803
804 " gitdir or home {{{2
805 " from derek wyatt:
806 " http://git.io/v3GAV
807 function! FindGitDirOrHome()
808 let filedir = expand('%:p:h')
809 if isdirectory(filedir)
810 let cmd = 'bash -c "(cd ' . filedir . '; git rev-parse --show-toplevel 2>/dev/null)"'
811 let gitdir = system(cmd)
812 if strlen(gitdir) == 0
813 return '~'
814 else
815 return gitdir[:-2]
816 endif
817 else
818 return '~'
819 endif
820 endfunction
821 command! Cd cd %:h
822 command! Cr execute('cd ' . FindGitDirOrHome())
823 command! LCd lcd %:h
824 command! LCr execute('lcd ' . FindGitDirOrHome())
825
826 " vim:set et sw=2 ts=2 tw=78: