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