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