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