]> git.rmz.io Git - dotfiles.git/blob - vim/vimrc
vim: auto-wrap comments, don't insert comment leader
[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
186 " whether to use a popup menu for Insert mode completion
187 set completeopt=longest,menuone,preview
188
189 " tabs and indent {{{2
190 set shiftwidth=4 " number of spaces used for each step of (auto)indent
191 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
192 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
193 set shiftround " round to 'shiftwidth' for "<<" and ">>"
194 set expandtab " expand <Tab> to spaces in Insert mode
195 set autoindent
196
197 set pastetoggle=<F11> " key sequence to toggle paste mode
198
199 " folding {{{2
200 set foldmethod=marker " folding type
201 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
202
203 " open folds when jumping to line
204 set foldopen+=jump
205
206 " save and restore folds
207 set viewoptions=cursor " only save cursor position
208
209 " diff mode {{{2
210 set diffopt+=filler " show filler lines
211 set diffopt+=vertical " always vertical split
212 set diffopt+=iwhite " ignore white space
213
214 " reading and writing files {{{2
215 set modeline " read modelines
216 set modelines=2 " only check first/last 2 lines
217
218 set writebackup " write a backup file before overwriting a file
219 set backup " keep a backup after owerwriting a file
220 set backupdir=$XDG_CACHE_HOME/vim/backup//
221
222 set backupskip+=.netrc " skip netrc
223 set backupskip+=/dev/shm/pass* " skip passwordstore files
224
225 set undofile " persistent undo history
226 set undodir=$XDG_CACHE_HOME/vim/undo//
227
228 augroup undoskip
229 au!
230 au BufWritePre .netrc setlocal noundofile
231 au BufWritePre /dev/shm/pass* setlocal noundofile
232 au BufWritePre /tmp/* setlocal noundofile
233 augroup END
234
235 set autowrite " automatically write a file when leaving a modified buffer
236 set autoread " automatically read a file that has been modified
237
238 " the swap file {{{2
239 set noswapfile
240 set directory=$XDG_CACHE_HOME/vim/swap//
241
242 " command line editing {{{2
243 set history=5000 " how many command lines are remembered
244 set wildmenu " command-line completion shows a list of matches
245 set wildmode=longest:full,full " specifies how command line completion works
246
247 set wildignore+=.hg,.git,.svn " Version control
248 set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
249 set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
250 set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
251 set wildignore+=*.spl " compiled spelling word lists
252 set wildignore+=*.sw? " Vim swap files
253 set wildignore+=*.luac " Lua byte code
254 set wildignore+=*.pyc " Python byte code
255 set wildignore+=*.orig " Merge resolution files
256
257 " various {{{2
258 set virtualedit=all " let cursor move past last char in <C-V> mode
259 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
260
261 set viewdir=$XDG_CACHE_HOME/vim/view//
262
263 " autocmds {{{1
264 " Resize splits when the window is resized {{{2
265 augroup resize
266 au!
267 autocmd VimResized * :wincmd =
268 augroup END
269
270 " Only show cursorline in the current window and in normal mode {{{2
271 augroup cline
272 au!
273 au WinLeave,InsertEnter * set nocursorline
274 au WinEnter,InsertLeave * set cursorline
275 augroup END
276
277 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
278 augroup ft_stdin
279 au!
280 au StdinReadPost * :set buftype=nofile
281 augroup END
282
283 " Jump to last known cursor position {{{2
284 augroup cursor_pos
285 au!
286 " blacklist certain filetype
287 let blacklist = ['gitcommit']
288 autocmd BufReadPost *
289 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
290 \ exe "normal! g`\"" |
291 \ endif
292 augroup END
293
294 " bindings {{{1
295
296 " allow both <space> and / to be <leader>
297 map <space> <leader>
298
299 " make
300 nnoremap <leader>r :make<cr>
301 nnoremap <leader><cr> :make<cr>
302
303 " unhighlight search
304 nnoremap <silent> <Leader>/ :silent nohl<CR>
305
306 " Tabs
307 nnoremap <leader>[ :tabprev<cr>
308 nnoremap <leader>] :tabnext<cr>
309
310 " paste from selection
311 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
312 " paste from clipboard
313 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
314
315 " Clean trailing whitespace
316 nnoremap <silent> <leader>ww m':%s/\s\+$//<cr>:let @/=''<cr>``zz
317
318 " Source
319 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
320 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
321
322 " jump to last cursor position
323 noremap ' `
324
325 " Select (charwise) the contents of the current line, excluding indentation.
326 nnoremap vv ^vg_
327
328 " Unfuck my screen
329 nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
330
331 " Ranger
332 " nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
333 " nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
334
335 " Use sane regexes.
336 nnoremap / /\v
337 vnoremap / /\v
338 cnoremap s/ s/\v
339
340 " display the number of matches for the last search
341 nmap <Leader># :%s:<C-R>/::gn<CR>
342
343 " center cursor after search and open folds
344 nnoremap n nzzzv
345 nnoremap N Nzzzv
346
347 " same when jumping around
348 nnoremap g; g;zzzv
349 nnoremap g, g,zzzv
350 nnoremap <c-o> <c-o>zzzv
351 nnoremap <c-i> <c-i>zzzv
352
353 " Not using the default mappings of 'To line from top/bottom'
354 noremap H ^
355 noremap L $
356 vnoremap H ^
357 vnoremap L g_
358
359 " Heresy, emacs insert bindings
360 inoremap <C-A> <Esc>I
361 inoremap <C-E> <Esc>A
362 cnoremap <C-A> <Home>
363 cnoremap <C-E> <End>
364
365 " proper movement when lines are wrapped
366 noremap <expr> j (v:count == 0 ? 'gj' : 'j')
367 noremap <expr> k (v:count == 0 ? 'gk' : 'k')
368
369 " disable arrows
370 noremap <Up> <NOP>
371 noremap <Down> <NOP>
372 noremap <Left> <NOP>
373 noremap <Right> <NOP>
374 inoremap <Up> <NOP>
375 inoremap <Down> <NOP>
376 inoremap <Left> <NOP>
377 inoremap <Right> <NOP>
378 cnoremap <Up> <NOP>
379 cnoremap <Down> <NOP>
380 cnoremap <Left> <NOP>
381 cnoremap <Right> <NOP>
382 cnoremap <C-K> <Up>
383 cnoremap <C-J> <Down>
384 cnoremap <C-H> <Left>
385 cnoremap <C-L> <Right>
386
387 " close all folds open fold in cursor
388 nnoremap zx zMzxzt
389
390 map <F1> :ls<CR>:b<space>
391
392 nnoremap <C-L> <C-W>w
393 nnoremap <C-H> <C-W>W
394
395 "xterm mouse with middleclick paste
396 nnoremap <MiddleMouse> i<MiddleMouse>
397 vnoremap <MiddleMouse> s<MiddleMouse>
398
399 " fix legacy vi inconsistency
400 map Y y$
401
402 " allow repeat operator on visual
403 vnoremap . :normal .<CR>
404
405 " add line without changing position or leaving mode
406 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
407 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
408
409 " Don't use Ex mode, use Q for formatting
410 map Q gq
411
412 " break undo sequence before removing word
413 inoremap <C-W> <C-G>u<C-W>
414
415 nnoremap coe :set <C-R>=&expandtab ? 'noexpandtab' : 'expandtab'<CR><CR>
416 nnoremap [oe :set expandtab<CR>
417 nnoremap ]oe :set noexpandtab<CR>
418
419 for idt in range(1,8)
420 exe 'nnoremap co'.idt.' :set tabstop='.idt.' shiftwidth='.idt.' softtabstop='.idt.'<CR>'
421 endfor
422
423 " space will toggle current fold in normal mode
424 nnoremap <leader><Space> za
425 " create folds around visual selection
426 vnoremap <leader><Space> zf
427
428 autocmd BufWinLeave *.* mkview
429 autocmd BufWinEnter *.* silent loadview
430
431 " save with sudo
432 cabbrev w!! w !sudo tee % > /dev/null
433
434 " uppercase previous word
435 inoremap <C-C> <Esc>gUiwgi
436
437 " http://git.io/v3ZeU
438 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>
439
440 " commands {{{1
441 command! Cd lcd %:h
442 command! Cr execute('lcd ' . FindGitDirOrHome())
443
444 " plugins options {{{1
445 " airline {{{2
446 let g:airline#extensions#whitespace#enabled = 1
447 let g:airline#extensions#tabline#enabled = 1
448 let g:airline_powerline_fonts = 1
449
450 " checkattach {{{2
451 let g:checkattach_filebrowser = 'ranger'
452 let g:checkattach_once = 'y'
453
454 " delimitmate {{{2
455 let delimitMate_expand_cr = 2
456 let g:delimitMate_expand_space = 1
457
458 " fswitch {{{2
459 nnoremap <silent> <Leader>ff :FSHere<CR>
460 nnoremap <silent> <Leader>fl :FSRight<CR>
461 nnoremap <silent> <Leader>fh :FSLeft<CR>
462 nnoremap <silent> <Leader>fj :FSBelow<CR>
463 nnoremap <silent> <Leader>fk :FSAbove<CR>
464 nnoremap <silent> <Leader>fL :FSSplitRight<CR>
465 nnoremap <silent> <Leader>fH :FSSplitLeft<CR>
466 nnoremap <silent> <Leader>fJ :FSSplitBelow<CR>
467 nnoremap <silent> <Leader>fK :FSSplitAbove<CR>
468
469 " fugitive {{{2
470 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
471 " delete fugitive buffers when closed
472 autocmd BufReadPost fugitive://* set bufhidden=delete
473
474 nnoremap <silent> <leader>gs :Gstatus<CR>
475 nnoremap <silent> <leader>gd :Gdiff<CR>
476 nnoremap <silent> <leader>gc :Gcommit -v<CR>
477 nnoremap <silent> <leader>ga :Gwrite<cr>
478 nnoremap <silent> <leader>gb :Gblame<cr>
479
480 " Gundo {{{2
481 nnoremap <F7> :GundoToggle<CR>
482
483 " indent-guides {{{2
484 let g:indent_guides_default_mapping = 0
485 let g:indent_guides_guide_size = 1
486 nmap <silent> cog <Plug>IndentGuidesToggle
487 nmap <silent> [og <Plug>IndentGuidesEnable
488 nmap <silent> ]og <Plug>IndentGuidesDisable
489
490 " python-mode {{{2
491
492 let g:pymode_rope_completion = 0
493 let g:pymode_rope = 0
494 let g:pymode_folding = 1
495 let g:pymode_lint_ignore = "E221,E266,E501"
496 let g:pymode_syntax_space_errors = 0 " don't bother me when I'm typing
497
498 " synastic {{{2
499 let g:syntastic_enable_highlighting = 0
500 let g:syntastic_error_symbol='E'
501 let g:syntastic_style_error_symbol='S'
502 let g:syntastic_warning_symbol='W'
503 let g:syntastic_style_warning_symbol='S'
504 let g:syntastic_always_populate_loc_list=1
505 nmap <silent> <leader>y :SyntasticCheck<cr>
506
507 if ! &diff
508 let g:syntastic_check_on_open=1
509 endif
510
511 " tagbar {{{2
512 map <F5> :TagbarToggle<cr>
513 let g:tagbar_sort = 0
514 let g:tagbar_compact = 1
515 let g:tagbar_autoshowtag = 1
516 let g:tagbar_width = 25
517 let g:tagbar_iconchars = ['+', '-']
518
519 " ultisnips {{{2
520 let g:UltiSnipsEditSplit = 'vertical'
521 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
522 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
523 let g:UltiSnipsExpandTrigger = "<tab>"
524 let g:UltiSnipsJumpForwardTrigger = "<tab>"
525 let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
526
527 " UltiSnips completion function that tries to expand a snippet. If there's no
528 " snippet for expanding, it checks for completion window and if it's shown,
529 " selects first element. If there's no completion window it tries to jump to
530 " next placeholder. If there's no placeholder it just returns TAB key
531 " https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-15451411
532 function! g:UltiSnips_Complete()
533 call UltiSnips#ExpandSnippet()
534 if g:ulti_expand_res == 0
535 if pumvisible()
536 return "\<C-n>"
537 else
538 call UltiSnips#JumpForwards()
539 if g:ulti_jump_forwards_res == 0
540 return "\<TAB>"
541 endif
542 endif
543 endif
544 return ""
545 endfunction
546 au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
547 let g:UltiSnipsListSnippets="<c-e>"
548
549 " unite {{{2
550 call unite#filters#matcher_default#use(['matcher_fuzzy'])
551 call unite#custom#profile('default', 'context', {
552 \ 'winheight': 20,
553 \ 'direction': 'botright'
554 \ })
555
556 nnoremap [unite] <Nop>
557 nmap <leader>u [unite]
558
559 " unite-grep {{{3
560 " seems not respected
561 let g:unite_source_grep_max_candidates = 2000
562 if executable('ag')
563 " Use ag in unite grep source.
564 let g:unite_source_grep_command = 'ag'
565 let g:unite_source_grep_default_opts = '--smart-case -w --vimgrep --hidden --ignore ''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
566 let g:unite_source_grep_recursive_opt = ''
567 end
568 nnoremap <silent> [unite]a :<C-u>Unite grep -input=\12\17<CR>
569 command! -nargs=1 Ag Unite grep -input=<args>
570
571 " unite-file_rec {{{3
572 if executable('ag')
573 " Use ag in unite rec source
574 let g:unite_source_rec_async_command = 'ag --follow --nocolor --nogroup --hidden -g ""'
575 end
576 nnoremap <silent> [unite]f :<C-u>Unite -start-insert file_rec/async<CR>
577
578 " unite-buffer {{{3
579 call unite#custom#default_action('buffer', 'goto')
580 nnoremap <silent> [unite]b :<C-u>Unite buffer<CR>
581
582 " unite-menu {{{3
583 let g:unite_source_menu_menus = {}
584 let g:unite_source_menu_menus.fugitive = { 'description' : 'fugitive menu'}
585 let g:unite_source_menu_menus.fugitive.command_candidates = {
586 \ 'Gstatus <Leader>gs' : 'Gstatus',
587 \ 'Gcommit -v <Leader>gc' : 'Gcommit -v',
588 \ 'Glog' : 'Glog',
589 \}
590
591 nnoremap <silent> <leader>gg :<C-u>Unite menu:fugitive<CR>
592
593 let g:unite_source_history_yank_enable = 1
594 nnoremap <silent> [unite]p :<C-u>Unite history/yank<CR>
595
596 " yankring {{{2
597 nnoremap <silent> <leader>p :YRShow<cr>
598 let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
599 let g:yankring_replace_n_pkey = ''
600 let g:yankring_replace_n_nkey = ''
601
602 " map Y to y$ for the yank ring
603 function! YRRunAfterMaps()
604 nnoremap Y :<C-U>YRYankCount 'y$'<CR>
605 endfunction
606
607 " youcompleteme {{{2
608 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
609 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
610 let g:ycm_extra_conf_vim_data = ['getcwd()']
611 let g:ycm_add_preview_to_completeopt = 1
612 let g:ycm_autoclose_preview_window_after_insertion = 0
613 "let g:ycm_extra_conf_vim_data = ['%:p']
614 nnoremap <leader>jd :YcmCompleter GoTo<CR>
615
616 " vim-easy-align {{{2
617 " start interactive EasyAlign in visual mode
618 vmap <Enter> <Plug>(EasyAlign)
619 nmap ga <Plug>(EasyAlign)
620
621 " vim-json {{{2
622 let g:vim_json_syntax_conceal = 0
623
624 " vim-latex {{{2
625 let g:tex_flavor='latex'
626 let g:Tex_DefaultTargetFormat='pdf'
627 let g:Tex_MultipleCompileFormats='pdf'
628
629 " vim-sneak {{{2
630 let g:sneak#streak = 1
631 let g:sneak#target_labels = "aoeuisnthdpylrcgfqjkxzmwvz" " dvorak
632 let g:sneak#use_ic_scs = 1 " follow 'ignorecase' and 'smartcase'
633
634 " sneaky f and t
635 nmap f <Plug>Sneak_f
636 nmap F <Plug>Sneak_F
637 xmap f <Plug>Sneak_f
638 xmap F <Plug>Sneak_F
639 omap f <Plug>Sneak_f
640 omap F <Plug>Sneak_F
641 nmap t <Plug>Sneak_t
642 nmap T <Plug>Sneak_T
643 xmap t <Plug>Sneak_t
644 xmap T <Plug>Sneak_T
645 omap t <Plug>Sneak_t
646 omap T <Plug>Sneak_T
647
648 " functions {{{1
649
650 " Convenient command to see the difference between the current buffer and the
651 " file it was loaded from, thus the changes you made.
652 " Only define it when not defined already.
653 if !exists(":DiffOrig")
654 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
655 \ | wincmd p | diffthis
656 endif
657
658 " edit configs {{{2
659 function! EditConfig(what)
660 let l:dir = split(&runtimepath,',')[0]
661 if a:what == 'vimrc'
662 let l:file = expand($MYVIMRC)
663 elseif ! isdirectory(globpath(l:dir, a:what))
664 echoe a:what." is not valid!"
665 elseif empty(&filetype)
666 echoe 'filetype is empty!'
667 else
668 let l:file = l:dir.'/'.a:what.'/'.&filetype.'.vim'
669 endif
670
671 execute ':vsplit '.file
672 execute ':lcd %:p:h'
673 endf
674 nmap <leader>ev :call EditConfig('vimrc')<CR>
675 nmap <leader>ef :call EditConfig('ftplugin')<CR>
676 nmap <leader>es :call EditConfig('syntax')<CR>
677 nmap <leader>ei :call EditConfig('indent')<CR>
678 nmap <leader>eu :UltiSnipsEdit<CR>:lcd %:p:h<CR>
679
680 " spell check {{{2
681 " http://tex.stackexchange.com/a/52932
682 let g:myLangList=["en_gb","en_us","de","fr"]
683
684 function! ToggleSpell()
685 if !exists("b:myLang")
686 let b:myLang=0
687 endif
688 execute "setlocal spell!"
689 if (&spell)
690 echo "setlocal spelllang=" g:myLangList[b:myLang]
691 endif
692 endfunction
693
694 function! SwitchSpell()
695 if !exists("b:myLang")
696 let b:myLang=0
697 endif
698 if (&spell)
699 let b:myLang=b:myLang+1
700 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
701 endif
702 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
703 echo "setlocal spelllang=" g:myLangList[b:myLang]
704 endfunction
705
706 nnoremap <silent> coS :call SwitchSpell()<CR>
707 " fix spelling with first choice
708 nnoremap <Leader>f 1z=
709
710 " gitdir or home {{{2
711 " from derek wyatt:
712 " http://git.io/v3GAV
713 function! FindGitDirOrHome()
714 let filedir = expand('%:p:h')
715 if isdirectory(filedir)
716 let cmd = 'bash -c "(cd ' . filedir . '; git rev-parse --show-toplevel 2>/dev/null)"'
717 let gitdir = system(cmd)
718 if strlen(gitdir) == 0
719 return '~'
720 else
721 return gitdir[:-2]
722 endif
723 else
724 return '~'
725 endif
726 endfunction
727
728 " vim:set et sw=2 ts=2 tw=78: