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