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