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/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'
44 Plugin 'sirver/ultisnips'
45 Plugin 'honza/vim-snippets'
48 Plugin 'kana/vim-textobj-user'
49 Plugin 'julian/vim-textobj-variable-segment'
50 Plugin 'sgur/vim-textobj-parameter'
53 Plugin 'ompugao/ros.vim'
54 Plugin 'ompugao/ctrlp-ros'
56 " seems to have problems right now... may be add later?
57 " Plugin 'jalcine/cmake.vim'
58 " Plugin 'powerman/vim-plugin-viewdoc'
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'
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'
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
83 filetype plugin indent on
90 " put $ and the end of text to be replaced with 'cw' and the likes
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
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
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
108 set lazyredraw " don't redraw while executing macros
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
116 au InsertEnter * :set listchars-=trail:·
117 au InsertLeave * :set listchars+=trail:·
120 set scrolloff=5 " number of screen lines to show around the cursor
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
475 let g:pymode_rope_completion = 0
476 let g:pymode_rope = 0
477 let g:pymode_folding = 1
478 let g:pymode_lint_ignore = "E221,E266,E501"
479 let g:pymode_syntax_space_errors = 0 " don't bother me when I'm typing
482 let g:syntastic_enable_highlighting = 0
483 let g:syntastic_error_symbol='E'
484 let g:syntastic_style_error_symbol='S'
485 let g:syntastic_warning_symbol='W'
486 let g:syntastic_style_warning_symbol='S'
487 let g:syntastic_always_populate_loc_list=1
488 nmap <silent> <leader>y :SyntasticCheck<cr>
491 let g:syntastic_check_on_open=1
495 map <F5> :TagbarToggle<cr>
496 let g:tagbar_sort = 0
497 let g:tagbar_compact = 1
498 let g:tagbar_autoshowtag = 1
499 let g:tagbar_width = 25
500 let g:tagbar_iconchars = ['+', '-']
503 let g:UltiSnipsEditSplit = 'vertical'
504 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
505 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
506 let g:UltiSnipsExpandTrigger = "<tab>"
507 let g:UltiSnipsJumpForwardTrigger = "<tab>"
508 let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
510 " UltiSnips completion function that tries to expand a snippet. If there's no
511 " snippet for expanding, it checks for completion window and if it's shown,
512 " selects first element. If there's no completion window it tries to jump to
513 " next placeholder. If there's no placeholder it just returns TAB key
514 " https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-15451411
515 function! g:UltiSnips_Complete()
516 call UltiSnips#ExpandSnippet()
517 if g:ulti_expand_res == 0
521 call UltiSnips#JumpForwards()
522 if g:ulti_jump_forwards_res == 0
529 au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
530 let g:UltiSnipsListSnippets="<c-e>"
533 call unite#filters#matcher_default#use(['matcher_fuzzy'])
534 call unite#custom#profile('default', 'context', {
536 \ 'direction': 'botright'
539 nnoremap [unite] <Nop>
540 nmap <leader>u [unite]
543 " seems not respected
544 let g:unite_source_grep_max_candidates = 2000
546 " Use ag in unite grep source.
547 let g:unite_source_grep_command = 'ag'
548 let g:unite_source_grep_default_opts = '--smart-case -w --vimgrep --hidden --ignore ''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
549 let g:unite_source_grep_recursive_opt = ''
551 nnoremap <silent> [unite]a :<C-u>Unite grep -input=
\12\17<CR>
552 command! -nargs=1 Ag Unite grep -input=<args>
554 " unite-file_rec {{{3
556 " Use ag in unite rec source
557 let g:unite_source_rec_async_command = 'ag --follow --nocolor --nogroup --hidden -g ""'
559 nnoremap <silent> [unite]f :<C-u>Unite -start-insert file_rec/async<CR>
562 call unite#custom#default_action('buffer', 'goto')
563 nnoremap <silent> [unite]b :<C-u>Unite buffer<CR>
566 let g:unite_source_menu_menus = {}
567 let g:unite_source_menu_menus.fugitive = { 'description' : 'fugitive menu'}
568 let g:unite_source_menu_menus.fugitive.command_candidates = {
569 \ 'Gstatus <Leader>gs' : 'Gstatus',
570 \ 'Gcommit -v <Leader>gc' : 'Gcommit -v',
574 nnoremap <silent> <leader>gg :<C-u>Unite menu:fugitive<CR>
576 let g:unite_source_history_yank_enable = 1
577 nnoremap <silent> [unite]p :<C-u>Unite history/yank<CR>
580 nnoremap <silent> <leader>p :YRShow<cr>
581 let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
582 let g:yankring_replace_n_pkey = ''
583 let g:yankring_replace_n_nkey = ''
585 " map Y to y$ for the yank ring
586 function! YRRunAfterMaps()
587 nnoremap Y :<C-U>YRYankCount 'y$'<CR>
591 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
592 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
593 let g:ycm_extra_conf_vim_data = ['getcwd()']
594 let g:ycm_add_preview_to_completeopt = 1
595 let g:ycm_autoclose_preview_window_after_insertion = 0
596 "let g:ycm_extra_conf_vim_data = ['%:p']
597 nnoremap <leader>jd :YcmCompleter GoTo<CR>
599 " vim-easy-align {{{2
600 " start interactive EasyAlign in visual mode
601 vmap <Enter> <Plug>(EasyAlign)
602 nmap ga <Plug>(EasyAlign)
605 let g:vim_json_syntax_conceal = 0
608 let g:tex_flavor='latex'
609 let g:Tex_DefaultTargetFormat='pdf'
610 let g:Tex_MultipleCompileFormats='pdf'
613 let g:sneak#streak = 1
614 let g:sneak#target_labels = "aoeuisnthdpylrcgfqjkxzmwvz" " dvorak
615 let g:sneak#use_ic_scs = 1 " follow 'ignorecase' and 'smartcase'
633 " Convenient command to see the difference between the current buffer and the
634 " file it was loaded from, thus the changes you made.
635 " Only define it when not defined already.
636 if !exists(":DiffOrig")
637 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
638 \ | wincmd p | diffthis
642 function! EditConfig(what)
643 let l:dir = split(&runtimepath,',')[0]
645 let l:file = expand($MYVIMRC)
646 elseif ! isdirectory(globpath(l:dir, a:what))
647 echoe a:what." is not valid!"
648 elseif empty(&filetype)
649 echoe 'filetype is empty!'
651 let l:file = l:dir.'/'.a:what.'/'.&filetype.'.vim'
654 execute ':vsplit '.file
657 nmap <leader>ev :call EditConfig('vimrc')<CR>
658 nmap <leader>ef :call EditConfig('ftplugin')<CR>
659 nmap <leader>es :call EditConfig('syntax')<CR>
660 nmap <leader>ei :call EditConfig('indent')<CR>
661 nmap <leader>eu :UltiSnipsEdit<CR>:lcd %:p:h<CR>
664 " http://tex.stackexchange.com/a/52932
665 let g:myLangList=["en_gb","en_us","de","fr"]
667 function! ToggleSpell()
668 if !exists("b:myLang")
671 execute "setlocal spell!"
673 echo "setlocal spelllang=" g:myLangList[b:myLang]
677 function! SwitchSpell()
678 if !exists("b:myLang")
682 let b:myLang=b:myLang+1
683 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
685 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
686 echo "setlocal spelllang=" g:myLangList[b:myLang]
689 nnoremap <silent> coS :call SwitchSpell()<CR>
690 " fix spelling with first choice
691 nnoremap <Leader>f 1z=
693 " gitdir or home {{{2
695 " http://git.io/v3GAV
696 function! FindGitDirOrHome()
697 let filedir = expand('%:p:h')
698 if isdirectory(filedir)
699 let cmd = 'bash -c "(cd ' . filedir . '; git rev-parse --show-toplevel 2>/dev/null)"'
700 let gitdir = system(cmd)
701 if strlen(gitdir) == 0
711 " vim:set et sw=2 ts=2 tw=78: