3 " Author: Samir Benmendil <samir.benmendil[at]gmail[dot]com>
8 set runtimepath& " reset rtp
9 " remove all autocommands
12 set runtimepath+=$XDG_DATA_HOME/vim/vundle
13 call vundle#rc('$XDG_DATA_HOME/vim')
15 Plugin 'gmarik/vundle'
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'
45 Plugin 'sirver/ultisnips'
46 Plugin 'honza/vim-snippets'
49 Plugin 'kana/vim-textobj-user'
50 Plugin 'julian/vim-textobj-variable-segment'
51 Plugin 'sgur/vim-textobj-parameter'
54 Plugin 'ompugao/ros.vim'
55 Plugin 'ompugao/ctrlp-ros'
57 " seems to have problems right now... may be add later?
58 " Plugin 'jalcine/cmake.vim'
59 " Plugin 'powerman/vim-plugin-viewdoc'
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'
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'
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
84 filetype plugin indent on
91 " put $ and the end of text to be replaced with 'cw' and the likes
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
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
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
109 set lazyredraw " don't redraw while executing macros
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
117 au InsertEnter * :set listchars-=trail:·
118 au InsertLeave * :set listchars+=trail:·
121 set sidescroll=1 " number of collumns to scroll
122 set sidescrolloff=1 " don't scroll over the listchars
124 set fillchars=diff:⣿,vert:│
126 set nonumber " show the line number for each line
127 set norelativenumber " show the relative line number for each line
129 " syntax, highlighting and spelling {{{2
130 set synmaxcol=800 " don't highlight long lines
132 set dictionary=spell " list of dictionary files for keyword completion
136 " multiple windows {{{2
137 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
139 set previewheight=20 " default height for the preview window
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
149 " using the mouse {{{2
150 set mouse=rnv " list of flags for using the mouse
151 set ttymouse=xterm " type of mouse
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
160 set backspace=indent,eol,start " allow backspacing over everything in insert mode
162 set showmatch " Show matching brackets.
164 set nojoinspaces " don't use two spaces after '.' when joining a line
165 set formatoptions=jcrnql
167 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
169 set complete=.,w,b,u,t
170 " whether to use a popup menu for Insert mode completion
171 set completeopt=longest,menuone,preview
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
181 set pastetoggle=<F11> " key sequence to toggle paste mode
184 set foldmethod=marker " folding type
185 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
187 " open folds when jumping to line
190 " save and restore folds
191 set viewoptions=cursor " only save cursor position
194 " vertical splits and ignore white space in diffs
195 set diffopt=filler,vertical,iwhite
197 " reading and writing files {{{2
198 set modeline " read modelines
199 set modelines=2 " only check first/last 2 lines
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//
205 set backupskip+=.netrc " skip netrc
206 set backupskip+=/dev/shm/pass* " skip passwordstore files
208 set undofile " persistent undo history
209 set undodir=$XDG_CACHE_HOME/vim/undo//
213 au BufWritePre .netrc setlocal noundofile
214 au BufWritePre /dev/shm/pass* setlocal noundofile
215 au BufWritePre /tmp/* setlocal noundofile
218 set autowrite " automatically write a file when leaving a modified buffer
219 set autoread " automatically read a file that has been modified
223 set directory=$XDG_CACHE_HOME/vim/swap//
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
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
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
244 set viewdir=$XDG_CACHE_HOME/vim/view//
247 " Resize splits when the window is resized {{{2
250 autocmd VimResized * :wincmd =
253 " Only show cursorline in the current window and in normal mode {{{2
256 au WinLeave,InsertEnter * set nocursorline
257 au WinEnter,InsertLeave * set cursorline
260 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
263 au StdinReadPost * :set buftype=nofile
266 " Jump to last known cursor position {{{2
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`\"" |
279 " allow both <space> and / to be <leader>
283 nnoremap <leader>r :make<cr>
284 nnoremap <leader><cr> :make<cr>
287 nnoremap <silent> <Leader>/ :silent nohl<CR>
290 nnoremap <leader>[ :tabprev<cr>
291 nnoremap <leader>] :tabnext<cr>
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>
298 " Clean trailing whitespace
299 nnoremap <silent> <leader>ww m':%s/\s\+$//<cr>:let @/=''<cr>``zz
302 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
303 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
305 " jump to last cursor position
308 " Select (charwise) the contents of the current line, excluding indentation.
312 nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
315 " nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
316 " nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
323 " display the number of matches for the last search
324 nmap <Leader># :%s:<C-R>/::gn<CR>
326 " center cursor after search and open folds
330 " same when jumping around
333 nnoremap <c-o> <c-o>zzzv
334 nnoremap <c-i> <c-i>zzzv
336 " Not using the default mappings of 'To line from top/bottom'
342 " Heresy, emacs insert bindings
343 inoremap <C-A> <Esc>I
344 inoremap <C-E> <Esc>A
345 cnoremap <C-A> <Home>
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')
356 noremap <Right> <NOP>
358 inoremap <Down> <NOP>
359 inoremap <Left> <NOP>
360 inoremap <Right> <NOP>
362 cnoremap <Down> <NOP>
363 cnoremap <Left> <NOP>
364 cnoremap <Right> <NOP>
366 cnoremap <C-J> <Down>
367 cnoremap <C-H> <Left>
368 cnoremap <C-L> <Right>
370 " close all folds open fold in cursor
373 map <F1> :ls<CR>:b<space>
375 nnoremap <C-L> <C-W>w
376 nnoremap <C-H> <C-W>W
378 "xterm mouse with middleclick paste
379 nnoremap <MiddleMouse> i<MiddleMouse>
380 vnoremap <MiddleMouse> s<MiddleMouse>
382 " fix legacy vi inconsistency
385 " allow repeat operator on visual
386 vnoremap . :normal .<CR>
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>
392 " Don't use Ex mode, use Q for formatting
395 " break undo sequence before removing word
396 inoremap <C-W> <C-G>u<C-W>
398 nnoremap coe :set <C-R>=&expandtab ? 'noexpandtab' : 'expandtab'<CR><CR>
399 nnoremap [oe :set expandtab<CR>
400 nnoremap ]oe :set noexpandtab<CR>
402 for idt in range(1,8)
403 exe 'nnoremap co'.idt.' :set tabstop='.idt.' shiftwidth='.idt.' softtabstop='.idt.'<CR>'
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
411 autocmd BufWinLeave *.* mkview
412 autocmd BufWinEnter *.* silent loadview
415 cabbrev w!! w !sudo tee % > /dev/null
417 " uppercase previous word
418 inoremap <C-C> <Esc>gUiwgi
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>
425 command! Cr execute('lcd ' . FindGitDirOrHome())
427 " plugins options {{{1
429 let g:airline#extensions#whitespace#enabled = 1
430 let g:airline#extensions#tabline#enabled = 1
431 let g:airline_powerline_fonts = 1
434 let g:checkattach_filebrowser = 'ranger'
435 let g:checkattach_once = 'y'
438 let delimitMate_expand_cr = 2
439 let g:delimitMate_expand_space = 1
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>
453 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
454 " delete fugitive buffers when closed
455 autocmd BufReadPost fugitive://* set bufhidden=delete
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>
464 nnoremap <F7> :GundoToggle<CR>
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
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
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
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>
500 let g:syntastic_check_on_open=1
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 = ['+', '-']
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>"
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
530 call UltiSnips#JumpForwards()
531 if g:ulti_jump_forwards_res == 0
538 au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
539 let g:UltiSnipsListSnippets="<c-e>"
542 call unite#filters#matcher_default#use(['matcher_fuzzy'])
543 call unite#custom#profile('default', 'context', {
545 \ 'direction': 'botright'
548 nnoremap [unite] <Nop>
549 nmap <leader>u [unite]
552 " seems not respected
553 let g:unite_source_grep_max_candidates = 2000
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 = ''
560 nnoremap <silent> [unite]a :<C-u>Unite grep -input=
\12\17<CR>
561 command! -nargs=1 Ag Unite grep -input=<args>
563 " unite-file_rec {{{3
565 " Use ag in unite rec source
566 let g:unite_source_rec_async_command = 'ag --follow --nocolor --nogroup --hidden -g ""'
568 nnoremap <silent> [unite]f :<C-u>Unite -start-insert file_rec/async<CR>
571 call unite#custom#default_action('buffer', 'goto')
572 nnoremap <silent> [unite]b :<C-u>Unite buffer<CR>
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',
583 nnoremap <silent> <leader>gg :<C-u>Unite menu:fugitive<CR>
585 let g:unite_source_history_yank_enable = 1
586 nnoremap <silent> [unite]p :<C-u>Unite history/yank<CR>
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 = ''
594 " map Y to y$ for the yank ring
595 function! YRRunAfterMaps()
596 nnoremap Y :<C-U>YRYankCount 'y$'<CR>
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>
608 " vim-easy-align {{{2
609 " start interactive EasyAlign in visual mode
610 vmap <Enter> <Plug>(EasyAlign)
611 nmap ga <Plug>(EasyAlign)
614 let g:vim_json_syntax_conceal = 0
617 let g:tex_flavor='latex'
618 let g:Tex_DefaultTargetFormat='pdf'
619 let g:Tex_MultipleCompileFormats='pdf'
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'
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
651 function! EditConfig(what)
652 let l:dir = split(&runtimepath,',')[0]
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!'
660 let l:file = l:dir.'/'.a:what.'/'.&filetype.'.vim'
663 execute ':vsplit '.file
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>
673 " http://tex.stackexchange.com/a/52932
674 let g:myLangList=["en_gb","en_us","de","fr"]
676 function! ToggleSpell()
677 if !exists("b:myLang")
680 execute "setlocal spell!"
682 echo "setlocal spelllang=" g:myLangList[b:myLang]
686 function! SwitchSpell()
687 if !exists("b:myLang")
691 let b:myLang=b:myLang+1
692 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
694 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
695 echo "setlocal spelllang=" g:myLangList[b:myLang]
698 nnoremap <silent> coS :call SwitchSpell()<CR>
699 " fix spelling with first choice
700 nnoremap <Leader>f 1z=
702 " gitdir or home {{{2
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
720 " vim:set et sw=2 ts=2 tw=78: