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