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