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