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