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