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