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