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