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'
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 " moving around, searching and patterns {{{2
91 set incsearch " show match for partly typed search command
92 set ignorecase " ignore case when using a search pattern
93 set smartcase " override 'ignorecase' when pattern has upper case characters
94 set hlsearch " highlight all matches for the last used search pattern
96 set nostartofline " don't move the cursor to the first non-blank char of a line
97 set path=.,include/,../include/,/usr/include/c++/*,/opt/ros/hydro/include
99 " displaying text {{{2
100 set scrolloff=5 " number of screen lines to show around the cursor
101 set nowrap " long lines wrap
102 set linebreak " wrap long lines at a character in 'breakat'
103 set showbreak=↪ " show these chars for wrapped lines
105 set lazyredraw " don't redraw while executing macros
107 set list " show chars defined in 'listchars'
108 set listchars=tab:❭\ " list of strings used for list mode
109 set listchars+=extends:❯,precedes:❮
110 " Only shown when not in insert mode
113 au InsertEnter * :set listchars-=trail:·
114 au InsertLeave * :set listchars+=trail:·
117 set sidescroll=1 " number of collumns to scroll
118 set sidescrolloff=1 " don't scroll over the listchars
120 set fillchars=diff:⣿,vert:│
122 set nonumber " show the line number for each line
123 set norelativenumber " show the relative line number for each line
125 " syntax, highlighting and spelling {{{2
126 set synmaxcol=800 " don't highlight long lines
128 set dictionary=spell " list of dictionary files for keyword completion
132 " multiple windows {{{2
133 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
135 set previewheight=20 " default height for the preview window
139 " set splitbelow " a new window is put below of the current one
140 set splitright " a new window is put right of the current one
145 " using the mouse {{{2
146 set mouse=rnv " list of flags for using the mouse
147 set ttymouse=xterm " type of mouse
149 " messages and info {{{2
150 set showcmd " Show (partial) command in status line.
151 set ruler " show the cursor position all the time
152 set confirm " Ask what to do when closing unsaved documents
153 set shortmess=filnxtoOI " don't show intro message
156 set backspace=indent,eol,start " allow backspacing over everything in insert mode
158 set showmatch " Show matching brackets.
160 set nojoinspaces " don't use two spaces after '.' when joining a line
161 set formatoptions=jcrnql
163 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
165 set complete=.,w,b,u,t
166 " whether to use a popup menu for Insert mode completion
167 set completeopt=longest,menuone,preview
169 " tabs and indent {{{2
170 set shiftwidth=4 " number of spaces used for each step of (auto)indent
171 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
172 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
173 set shiftround " round to 'shiftwidth' for "<<" and ">>"
174 set expandtab " expand <Tab> to spaces in Insert mode
177 set pastetoggle=<F11> " key sequence to toggle paste mode
180 set foldmethod=marker " folding type
181 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
183 " save and restore folds
184 set viewoptions=cursor " only save cursor position
187 set diffopt=filler,vertical
189 " reading and writing files {{{2
190 set modeline " read modelines
191 set modelines=2 " only check first/last 2 lines
193 set writebackup " write a backup file before overwriting a file
194 set backup " keep a backup after owerwriting a file
195 set backupdir=$XDG_CACHE_HOME/vim/backup//
197 set backupskip+=.netrc " skip netrc
198 set backupskip+=/dev/shm/pass* " skip passwordstore files
200 set undofile " persistent undo history
201 set undodir=$XDG_CACHE_HOME/vim/undo//
205 au BufWritePre .netrc setlocal noundofile
206 au BufWritePre /dev/shm/pass* setlocal noundofile
207 au BufWritePre /tmp/* setlocal noundofile
210 set autowrite " automatically write a file when leaving a modified buffer
211 set autoread " automatically read a file that has been modified
215 set directory=$XDG_CACHE_HOME/vim/swap//
217 " command line editing {{{2
218 set history=5000 " how many command lines are remembered
219 set wildmenu " command-line completion shows a list of matches
220 set wildmode=longest:full,full " specifies how command line completion works
222 set wildignore+=.hg,.git,.svn " Version control
223 set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
224 set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
225 set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
226 set wildignore+=*.spl " compiled spelling word lists
227 set wildignore+=*.sw? " Vim swap files
228 set wildignore+=*.luac " Lua byte code
229 set wildignore+=*.pyc " Python byte code
230 set wildignore+=*.orig " Merge resolution files
233 set virtualedit=block " let cursor move past last char in <C-V> mode
234 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
236 set viewdir=$XDG_CACHE_HOME/vim/view//
239 " Resize splits when the window is resized {{{2
242 autocmd VimResized * :wincmd =
245 " Only show cursorline in the current window and in normal mode {{{2
248 au WinLeave,InsertEnter * set nocursorline
249 au WinEnter,InsertLeave * set cursorline
252 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
255 au StdinReadPost * :set buftype=nofile
258 " Jump to last known cursor position {{{2
261 " blacklist certain filetype
262 let blacklist = ['gitcommit']
263 autocmd BufReadPost *
264 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
265 \ exe "normal! g`\"" |
271 " allow both <space> and / to be <leader>
275 nnoremap <leader>r :make<cr>
276 nnoremap <leader><cr> :make<cr>
279 nnoremap <silent> <Leader>/ :silent nohl<CR>
282 nnoremap <leader>[ :tabprev<cr>
283 nnoremap <leader>] :tabnext<cr>
285 " paste from selection
286 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
287 " paste from clipboard
288 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
290 " Clean trailing whitespace
291 nnoremap <silent> <leader>ww m':%s/\s\+$//<cr>:let @/=''<cr>``zz
294 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
295 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
297 " jump to last cursor position
300 " Select (charwise) the contents of the current line, excluding indentation.
304 nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
307 " nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
308 " nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
315 " display the number of matches for the last search
316 nmap <Leader># :%s:<C-R>/::gn<CR>
318 " center cursor after search and open folds
322 " same when jumping around
325 nnoremap <c-o> <c-o>zzzv
326 nnoremap <c-i> <c-i>zzzv
328 " Not using the default mappings of 'To line from top/bottom'
334 " Heresy, emacs insert bindings
335 inoremap <c-a> <esc>I
336 inoremap <c-e> <esc>A
337 cnoremap <c-a> <home>
340 " proper movement when lines are wrapped
341 noremap <expr> j (v:count == 0 ? 'gj' : 'j')
342 noremap <expr> k (v:count == 0 ? 'gk' : 'k')
348 noremap <Right> <NOP>
350 inoremap <Down> <NOP>
351 inoremap <Left> <NOP>
352 inoremap <Right> <NOP>
354 cnoremap <Down> <NOP>
355 cnoremap <Left> <NOP>
356 cnoremap <Right> <NOP>
358 cnoremap <C-J> <Down>
359 cnoremap <C-H> <Left>
360 cnoremap <C-L> <Right>
362 " close all folds open fold in cursor
365 map <F1> :ls<CR>:b<space>
367 nnoremap <C-L> <C-W>w
368 nnoremap <C-H> <C-W>W
370 "xterm mouse with middleclick paste
371 nnoremap <MiddleMouse> i<MiddleMouse>
372 vnoremap <MiddleMouse> s<MiddleMouse>
374 " fix legacy vi inconsistency
377 " allow repeat operator on visual
378 vnoremap . :normal .<CR>
380 " add line without changing position or leaving mode
381 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
382 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
384 " Don't use Ex mode, use Q for formatting
387 " break undo sequence before removing word
388 inoremap <C-W> <C-G>u<C-W>
390 nnoremap coe :set <C-R>=&expandtab ? 'noexpandtab' : 'expandtab'<CR><CR>
391 nnoremap [oe :set expandtab<CR>
392 nnoremap ]oe :set noexpandtab<CR>
394 for idt in range(1,8)
395 exe 'nnoremap co'.idt.' :set tabstop='.idt.' shiftwidth='.idt.' softtabstop='.idt.'<CR>'
398 " space will toggle current fold in normal mode
399 nnoremap <leader><Space> za
400 " create folds around visual selection
401 vnoremap <leader><Space> zf
403 autocmd BufWinLeave *.* mkview
404 autocmd BufWinEnter *.* silent loadview
407 cnoremap w!! w !sudo tee % > /dev/null
409 " uppercase previous word
410 inoremap <C-C> <Esc>gUiwgi
412 " plugins options {{{1
414 let g:airline#extensions#whitespace#enabled = 1
415 let g:airline#extensions#tabline#enabled = 1
416 let g:airline_powerline_fonts = 1
419 let g:checkattach_filebrowser = 'ranger'
420 let g:checkattach_once = 'y'
423 let delimitMate_expand_cr = 2
424 let g:delimitMate_expand_space = 1
427 nnoremap <silent> <Leader>ff :FSHere<CR>
428 nnoremap <silent> <Leader>fl :FSRight<CR>
429 nnoremap <silent> <Leader>fh :FSLeft<CR>
430 nnoremap <silent> <Leader>fj :FSBelow<CR>
431 nnoremap <silent> <Leader>fk :FSAbove<CR>
432 nnoremap <silent> <Leader>fL :FSSplitRight<CR>
433 nnoremap <silent> <Leader>fH :FSSplitLeft<CR>
434 nnoremap <silent> <Leader>fJ :FSSplitBelow<CR>
435 nnoremap <silent> <Leader>fK :FSSplitAbove<CR>
438 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
439 " delete fugitive buffers when closed
440 autocmd BufReadPost fugitive://* set bufhidden=delete
442 nnoremap <silent> <leader>gs :Gstatus<CR>
443 nnoremap <silent> <leader>gd :Gdiff<CR>
444 nnoremap <silent> <leader>gc :Gcommit -v<CR>
445 nnoremap <silent> <leader>ga :Gwrite<cr>
446 nnoremap <silent> <leader>gb :Gblame<cr>
449 nnoremap <F7> :GundoToggle<CR>
452 let g:indent_guides_default_mapping = 0
453 let g:indent_guides_guide_size = 1
454 nmap <silent> cog <Plug>IndentGuidesToggle
455 nmap <silent> [og <Plug>IndentGuidesEnable
456 nmap <silent> ]og <Plug>IndentGuidesDisable
459 " open/close NERDTree with \e
460 nmap <Leader>e :NERDTreeToggle<CR>
461 nmap <F6> :NERDTreeToggle<CR>
462 " <space> to open files/dirs
463 let NERDTreeMapActivateNode='l'
464 " close vim if only NERDTree is open
465 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
469 let g:pymode_rope_completion = 0
470 let g:pymode_rope = 0
471 let g:pymode_folding = 1
472 let g:pymode_lint_ignore = "E221,E266,E501"
473 let g:pymode_syntax_space_errors = 0 " don't bother me when I'm typing
476 let g:syntastic_enable_highlighting = 0
477 let g:syntastic_error_symbol='E'
478 let g:syntastic_style_error_symbol='S'
479 let g:syntastic_warning_symbol='W'
480 let g:syntastic_style_warning_symbol='S'
481 let g:syntastic_always_populate_loc_list=1
482 nmap <silent> <leader>y :SyntasticCheck<cr>
485 let g:syntastic_check_on_open=1
489 map <F5> :TagbarToggle<cr>
490 let g:tagbar_sort = 0
491 let g:tagbar_compact = 1
492 let g:tagbar_autoshowtag = 1
493 let g:tagbar_width = 25
494 let g:tagbar_iconchars = ['+', '-']
497 let g:UltiSnipsEditSplit = 'vertical'
498 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
499 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
500 let g:UltiSnipsExpandTrigger = "<tab>"
501 let g:UltiSnipsJumpForwardTrigger = "<tab>"
502 let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
504 " UltiSnips completion function that tries to expand a snippet. If there's no
505 " snippet for expanding, it checks for completion window and if it's shown,
506 " selects first element. If there's no completion window it tries to jump to
507 " next placeholder. If there's no placeholder it just returns TAB key
508 " https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-15451411
509 function! g:UltiSnips_Complete()
510 call UltiSnips#ExpandSnippet()
511 if g:ulti_expand_res == 0
515 call UltiSnips#JumpForwards()
516 if g:ulti_jump_forwards_res == 0
523 au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
524 let g:UltiSnipsListSnippets="<c-e>"
527 call unite#filters#matcher_default#use(['matcher_fuzzy'])
528 call unite#custom#profile('default', 'context', {
530 \ 'direction': 'botright'
533 nnoremap [unite] <Nop>
534 nmap <leader>u [unite]
537 " seems not respected
538 let g:unite_source_grep_max_candidates = 2000
540 " Use ag in unite grep source.
541 let g:unite_source_grep_command = 'ag'
542 let g:unite_source_grep_default_opts = '--smart-case -w --vimgrep --hidden --ignore ''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
543 let g:unite_source_grep_recursive_opt = ''
545 nnoremap <silent> [unite]a :<C-u>Unite grep -input=
\12\17<CR>
546 command! -nargs=1 Ag Unite grep -input=<args>
548 " unite-file_rec {{{3
550 " Use ag in unite rec source
551 let g:unite_source_rec_async_command = 'ag --follow --nocolor --nogroup --hidden -g ""'
553 nnoremap <silent> [unite]f :<C-u>Unite -start-insert file_rec/async<CR>
556 call unite#custom#default_action('buffer', 'goto')
557 nnoremap <silent> [unite]b :<C-u>Unite buffer<CR>
560 let g:unite_source_menu_menus = {}
561 let g:unite_source_menu_menus.fugitive = { 'description' : 'fugitive menu'}
562 let g:unite_source_menu_menus.fugitive.command_candidates = {
563 \ 'Gstatus <Leader>gs' : 'Gstatus',
564 \ 'Gcommit -v <Leader>gc' : 'Gcommit -v',
568 nnoremap <silent> <leader>gg :<C-u>Unite menu:fugitive<CR>
570 let g:unite_source_history_yank_enable = 1
571 nnoremap <silent> [unite]p :<C-u>Unite history/yank<CR>
574 nnoremap <silent> <leader>p :YRShow<cr>
575 let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
576 let g:yankring_replace_n_pkey = ''
577 let g:yankring_replace_n_nkey = ''
579 " map Y to y$ for the yank ring
580 function! YRRunAfterMaps()
581 nnoremap Y :<C-U>YRYankCount 'y$'<CR>
585 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
586 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
587 let g:ycm_extra_conf_vim_data = ['getcwd()']
588 let g:ycm_add_preview_to_completeopt = 1
589 let g:ycm_autoclose_preview_window_after_insertion = 0
590 "let g:ycm_extra_conf_vim_data = ['%:p']
591 nnoremap <leader>jd :YcmCompleter GoTo<CR>
593 " vim-easy-align {{{2
594 " start interactive EasyAlign in visual mode
595 vmap <Enter> <Plug>(EasyAlign)
598 let g:vim_json_syntax_conceal = 0
601 let g:tex_flavor='latex'
602 let g:Tex_DefaultTargetFormat='pdf'
603 let g:Tex_MultipleCompileFormats='pdf'
606 let g:sneak#streak = 1
607 let g:sneak#target_labels = "aoeuisnthdpylrcgfqjkxzmwvz" " dvorak
608 let g:sneak#use_ic_scs = 1 " follow 'ignorecase' and 'smartcase'
626 " Convenient command to see the difference between the current buffer and the
627 " file it was loaded from, thus the changes you made.
628 " Only define it when not defined already.
629 if !exists(":DiffOrig")
630 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
631 \ | wincmd p | diffthis
635 function! EditConfig(what)
636 let l:dir = split(&runtimepath,',')[0]
638 let l:file = expand($MYVIMRC)
639 elseif ! isdirectory(globpath(l:dir, a:what))
640 echoe a:what." is not valid!"
641 elseif empty(&filetype)
642 echoe 'filetype is empty!'
644 let l:file = l:dir.'/'.a:what.'/'.&filetype.'.vim'
647 execute ':vsplit '.file
650 nmap <leader>ev :call EditConfig('vimrc')<CR>
651 nmap <leader>ef :call EditConfig('ftplugin')<CR>
652 nmap <leader>es :call EditConfig('syntax')<CR>
653 nmap <leader>ei :call EditConfig('indent')<CR>
654 nmap <leader>eu :UltiSnipsEdit<CR>:lcd %:p:h<CR>
657 " http://tex.stackexchange.com/a/52932
658 let g:myLangList=["en_gb","en_us","de","fr"]
660 function! ToggleSpell()
661 if !exists("b:myLang")
664 execute "setlocal spell!"
666 echo "setlocal spelllang=" g:myLangList[b:myLang]
670 function! SwitchSpell()
671 if !exists("b:myLang")
675 let b:myLang=b:myLang+1
676 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
678 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
679 echo "setlocal spelllang=" g:myLangList[b:myLang]
682 nnoremap <silent> coS :call SwitchSpell()<CR>
683 " fix spelling with first choice
684 nnoremap <Leader>f 1z=