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