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
102 set path+=../include/
103 set path+=/usr/include/c++/*
105 " displaying text {{{2
106 set nowrap " long lines wrap
107 set linebreak " wrap long lines at a character in 'breakat'
108 set showbreak=↪ " show these chars for wrapped lines
109 set breakindent " preserve indentation in wrapped text
111 set lazyredraw " don't redraw while executing macros
113 set list " show chars defined in 'listchars'
114 set listchars=tab:❭\ " list of strings used for list mode
115 set listchars+=extends:❯,precedes:❮
116 " Only shown when not in insert mode
117 au InsertLeave * :set listchars+=trail:·
120 au InsertEnter * :set listchars-=trail:·
121 au InsertLeave * :set listchars+=trail:·
124 set scrolloff=5 " number of screen lines to show around the cursor
125 set sidescroll=1 " number of collumns to scroll
126 set sidescrolloff=1 " don't scroll over the listchars
128 set fillchars=diff:⣿,vert:│
130 set nonumber " show the line number for each line
131 set norelativenumber " show the relative line number for each line
133 " syntax, highlighting and spelling {{{2
134 set synmaxcol=800 " don't highlight long lines
136 set dictionary=spell " list of dictionary files for keyword completion
140 " multiple windows {{{2
141 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
143 set previewheight=20 " default height for the preview window
147 " set splitbelow " a new window is put below of the current one
148 set splitright " a new window is put right of the current one
153 " using the mouse {{{2
154 set mouse=rnv " list of flags for using the mouse
155 set ttymouse=xterm " type of mouse
157 " messages and info {{{2
158 set showcmd " Show (partial) command in status line.
159 set ruler " show the cursor position all the time
160 set confirm " Ask what to do when closing unsaved documents
161 set shortmess=filnxtoOI " don't show intro message
164 set backspace=indent,eol,start " allow backspacing over everything in insert mode
166 set showmatch " Show matching brackets.
168 set nojoinspaces " don't use two spaces after '.' when joining a line
169 set formatoptions+=j " Delete comment leader when joining lines
170 set formatoptions+=c " Autowrap comments using textwidth
171 set formatoptions+=r " Insert comment leader after hitting <Enter>
172 set formatoptions+=n " Recognize numbered lists
173 set formatoptions+=q " Allow formatting of comments with "gq".
174 set formatoptions+=l " do not wrap lines that have been longer when starting insert mode already
175 set formatoptions+=t " Auto-wrap text using textwidth
176 set formatoptions-=o " Do not insert comment leader after hitting o or O in normal mode
178 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
180 set complete=. " scan the current buffer ( 'wrapscan' is ignored)
181 set complete+=w " scan buffers from other windows
182 set complete+=b " scan other loaded buffers that are in the buffer list
183 set complete+=u " scan the unloaded buffers that are in the buffer list
184 set complete+=t " scan tags
185 set complete+=i " scan current and included files
186 set complete+=kspell " use the currently active spell checking |spell|
188 " whether to use a popup menu for Insert mode completion
189 set completeopt=longest,menuone,preview
191 " tabs and indent {{{2
192 set shiftwidth=4 " number of spaces used for each step of (auto)indent
193 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
194 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
195 set shiftround " round to 'shiftwidth' for "<<" and ">>"
196 set expandtab " expand <Tab> to spaces in Insert mode
199 set pastetoggle=<F11> " key sequence to toggle paste mode
202 set foldmethod=marker " folding type
203 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
205 " open folds when jumping to line
208 " save and restore folds
209 set viewoptions=cursor " only save cursor position
212 set diffopt+=filler " show filler lines
213 set diffopt+=vertical " always vertical split
214 set diffopt+=iwhite " ignore white space
215 set diffopt+=context:10 " 10 lines context between changes
217 " reading and writing files {{{2
218 set modeline " read modelines
219 set modelines=2 " only check first/last 2 lines
221 set writebackup " write a backup file before overwriting a file
222 set backup " keep a backup after owerwriting a file
223 set backupdir=$XDG_CACHE_HOME/vim/backup//
225 set backupskip+=.netrc " skip netrc
226 set backupskip+=/dev/shm/pass* " skip passwordstore files
228 set undofile " persistent undo history
229 set undodir=$XDG_CACHE_HOME/vim/undo//
233 au BufWritePre .netrc setlocal noundofile
234 au BufWritePre /dev/shm/pass* setlocal noundofile
235 au BufWritePre /tmp/* setlocal noundofile
238 set autowrite " automatically write a file when leaving a modified buffer
239 set autoread " automatically read a file that has been modified
243 set directory=$XDG_CACHE_HOME/vim/swap//
245 " command line editing {{{2
246 set history=5000 " how many command lines are remembered
247 set wildmenu " command-line completion shows a list of matches
248 set wildmode=longest:full,full " specifies how command line completion works
250 set wildignore+=.hg,.git,.svn " Version control
251 set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
252 set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
253 set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
254 set wildignore+=*.spl " compiled spelling word lists
255 set wildignore+=*.sw? " Vim swap files
256 set wildignore+=*.luac " Lua byte code
257 set wildignore+=*.pyc " Python byte code
258 set wildignore+=*.orig " Merge resolution files
260 " language specific {{{2
261 set isfname-== " don't treat `=` as being part of filenames
264 set virtualedit=all " let cursor move past last char in <C-V> mode
265 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
267 set viewdir=$XDG_CACHE_HOME/vim/view//
269 set sessionoptions+=unix,slash " damn windows and it's silly ways
272 " Resize splits when the window is resized {{{2
275 autocmd VimResized * :wincmd =
278 " Only show cursorline in the current window and in normal mode {{{2
281 au WinLeave,InsertEnter * set nocursorline
282 au WinEnter,InsertLeave * set cursorline
285 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
288 au StdinReadPost * :set buftype=nofile
291 " Jump to last known cursor position {{{2
294 " blacklist certain filetype
295 let blacklist = ['gitcommit']
296 autocmd BufReadPost *
297 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
298 \ exe "normal! g`\"" |
304 " allow both <space> and / to be <leader>
308 nnoremap <leader>r :make<cr>
309 nnoremap <leader><cr> :make<cr>
312 nnoremap <silent> <Leader>/ :silent nohl<CR>
315 nnoremap <leader>[ :tabprev<cr>
316 nnoremap <leader>] :tabnext<cr>
318 " paste from selection
319 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
320 " paste from clipboard
321 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
323 " Clean trailing whitespace
324 nnoremap <silent> <leader>ww m':%s/\s\+$//<cr>:let @/=''<cr>``zz
327 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
328 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
330 " jump to last cursor position
333 " Select (charwise) the contents of the current line, excluding indentation.
337 nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
340 " nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
341 " nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
348 " display the number of matches for the last search
349 nmap <Leader># :%s:<C-R>/::gn<CR>
351 " center cursor after search and open folds
355 " same when jumping around
358 nnoremap <c-o> <c-o>zzzv
359 nnoremap <c-i> <c-i>zzzv
361 " Not using the default mappings of 'To line from top/bottom'
367 " Heresy, emacs insert bindings
368 inoremap <C-A> <Esc>I
369 inoremap <C-E> <Esc>A
370 cnoremap <C-A> <Home>
373 " proper movement when lines are wrapped
374 noremap <expr> j (v:count == 0 ? 'gj' : 'j')
375 noremap <expr> k (v:count == 0 ? 'gk' : 'k')
381 noremap <Right> <NOP>
383 inoremap <Down> <NOP>
384 inoremap <Left> <NOP>
385 inoremap <Right> <NOP>
387 cnoremap <Down> <NOP>
388 cnoremap <Left> <NOP>
389 cnoremap <Right> <NOP>
391 cnoremap <C-J> <Down>
392 cnoremap <C-H> <Left>
393 cnoremap <C-L> <Right>
395 " close all folds open fold in cursor
398 map <F1> :ls<CR>:b<space>
400 nnoremap <C-L> <C-W>w
401 nnoremap <C-H> <C-W>W
403 "xterm mouse with middleclick paste
404 nnoremap <MiddleMouse> i<MiddleMouse>
405 vnoremap <MiddleMouse> s<MiddleMouse>
407 " fix legacy vi inconsistency
410 " allow repeat operator on visual
411 vnoremap . :normal .<CR>
413 " add line without changing position or leaving mode
414 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
415 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
417 " Don't use Ex mode, use Q for formatting
420 " break undo sequence before removing word
421 inoremap <C-W> <C-G>u<C-W>
423 nnoremap coe :set <C-R>=&expandtab ? 'noexpandtab' : 'expandtab'<CR><CR>
424 nnoremap [oe :set expandtab<CR>
425 nnoremap ]oe :set noexpandtab<CR>
427 for idt in range(1,8)
428 exe 'nnoremap co'.idt.' :set tabstop='.idt.' shiftwidth='.idt.' softtabstop='.idt.'<CR>'
431 " space will toggle current fold in normal mode
432 nnoremap <leader><Space> za
433 " create folds around visual selection
434 vnoremap <leader><Space> zf
436 autocmd BufWinLeave *.* mkview
437 autocmd BufWinEnter *.* silent loadview
440 cabbrev w!! w !sudo tee % > /dev/null
442 " uppercase previous word
443 inoremap <C-C> <Esc>gUiwgi
445 " http://git.io/v3ZeU
446 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>
450 command! Cr execute('lcd ' . FindGitDirOrHome())
452 " plugins options {{{1
454 let g:airline#extensions#whitespace#enabled = 1
455 let g:airline#extensions#tabline#enabled = 1
456 let g:airline_powerline_fonts = 1
459 let g:checkattach_filebrowser = 'ranger'
460 let g:checkattach_once = 'y'
463 let delimitMate_expand_cr = 2
464 let g:delimitMate_expand_space = 1
467 nnoremap <silent> <Leader>ff :FSHere<CR>
468 nnoremap <silent> <Leader>fl :FSRight<CR>
469 nnoremap <silent> <Leader>fh :FSLeft<CR>
470 nnoremap <silent> <Leader>fj :FSBelow<CR>
471 nnoremap <silent> <Leader>fk :FSAbove<CR>
472 nnoremap <silent> <Leader>fL :FSSplitRight<CR>
473 nnoremap <silent> <Leader>fH :FSSplitLeft<CR>
474 nnoremap <silent> <Leader>fJ :FSSplitBelow<CR>
475 nnoremap <silent> <Leader>fK :FSSplitAbove<CR>
478 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
479 " delete fugitive buffers when closed
480 autocmd BufReadPost fugitive://* set bufhidden=delete
482 nnoremap <silent> <leader>gs :Gstatus<CR>
483 nnoremap <silent> <leader>gd :Gdiff<CR>
484 nnoremap <silent> <leader>gc :Gcommit -v<CR>
485 nnoremap <silent> <leader>ga :Gwrite<cr>
486 nnoremap <silent> <leader>gb :Gblame<cr>
489 nnoremap <F7> :GundoToggle<CR>
492 let g:indent_guides_default_mapping = 0
493 let g:indent_guides_guide_size = 1
494 nmap <silent> cog <Plug>IndentGuidesToggle
495 nmap <silent> [og <Plug>IndentGuidesEnable
496 nmap <silent> ]og <Plug>IndentGuidesDisable
500 let g:pymode_rope_completion = 0
501 let g:pymode_rope = 0
502 let g:pymode_folding = 1
503 let g:pymode_lint_ignore = "E221,E266,E501"
504 let g:pymode_syntax_space_errors = 0 " don't bother me when I'm typing
507 let g:syntastic_enable_highlighting = 0
508 let g:syntastic_error_symbol='E'
509 let g:syntastic_style_error_symbol='S'
510 let g:syntastic_warning_symbol='W'
511 let g:syntastic_style_warning_symbol='S'
512 let g:syntastic_always_populate_loc_list=1
513 nmap <silent> <leader>y :SyntasticCheck<cr>
516 let g:syntastic_check_on_open=1
520 map <F5> :TagbarToggle<cr>
521 let g:tagbar_sort = 0
522 let g:tagbar_compact = 1
523 let g:tagbar_autoshowtag = 1
524 let g:tagbar_width = 25
525 let g:tagbar_iconchars = ['+', '-']
528 let g:UltiSnipsEditSplit = 'vertical'
529 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
530 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
531 let g:UltiSnipsExpandTrigger = "<tab>"
532 let g:UltiSnipsJumpForwardTrigger = "<tab>"
533 let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
535 " UltiSnips completion function that tries to expand a snippet. If there's no
536 " snippet for expanding, it checks for completion window and if it's shown,
537 " selects first element. If there's no completion window it tries to jump to
538 " next placeholder. If there's no placeholder it just returns TAB key
539 " https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-15451411
540 function! g:UltiSnips_Complete()
541 call UltiSnips#ExpandSnippet()
542 if g:ulti_expand_res == 0
546 call UltiSnips#JumpForwards()
547 if g:ulti_jump_forwards_res == 0
554 au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
555 let g:UltiSnipsListSnippets="<c-e>"
558 call unite#filters#matcher_default#use(['matcher_fuzzy'])
559 call unite#custom#profile('default', 'context', {
561 \ 'direction': 'botright'
564 nnoremap [unite] <Nop>
565 nmap <leader>u [unite]
568 " seems not respected
569 let g:unite_source_grep_max_candidates = 2000
571 " Use ag in unite grep source.
572 let g:unite_source_grep_command = 'ag'
573 let g:unite_source_grep_default_opts = '--smart-case -w --vimgrep --hidden --ignore ''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
574 let g:unite_source_grep_recursive_opt = ''
576 nnoremap <silent> [unite]a :<C-u>Unite grep -input=
\12\17<CR>
577 command! -nargs=1 Ag Unite grep -input=<args>
579 " unite-file_rec {{{3
581 " Use ag in unite rec source
582 let g:unite_source_rec_async_command = 'ag --follow --nocolor --nogroup --hidden -g ""'
584 nnoremap <silent> [unite]f :<C-u>Unite -start-insert file_rec/async<CR>
587 call unite#custom#default_action('buffer', 'goto')
588 nnoremap <silent> [unite]b :<C-u>Unite buffer<CR>
591 let g:unite_source_menu_menus = {}
592 let g:unite_source_menu_menus.fugitive = { 'description' : 'fugitive menu'}
593 let g:unite_source_menu_menus.fugitive.command_candidates = {
594 \ 'Gstatus <Leader>gs' : 'Gstatus',
595 \ 'Gcommit -v <Leader>gc' : 'Gcommit -v',
599 nnoremap <silent> <leader>gg :<C-u>Unite menu:fugitive<CR>
601 let g:unite_source_history_yank_enable = 1
602 nnoremap <silent> [unite]p :<C-u>Unite history/yank<CR>
605 nnoremap <silent> <leader>p :YRShow<cr>
606 let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
607 let g:yankring_replace_n_pkey = ''
608 let g:yankring_replace_n_nkey = ''
610 " map Y to y$ for the yank ring
611 function! YRRunAfterMaps()
612 nnoremap Y :<C-U>YRYankCount 'y$'<CR>
616 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
617 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
618 let g:ycm_extra_conf_vim_data = ['getcwd()']
619 let g:ycm_add_preview_to_completeopt = 1
620 let g:ycm_autoclose_preview_window_after_insertion = 0
621 "let g:ycm_extra_conf_vim_data = ['%:p']
622 nnoremap <leader>jd :YcmCompleter GoTo<CR>
624 " vim-easy-align {{{2
625 " start interactive EasyAlign in visual mode
626 vmap <Enter> <Plug>(EasyAlign)
627 nmap ga <Plug>(EasyAlign)
630 let g:vim_json_syntax_conceal = 0
633 let g:tex_flavor='latex'
634 let g:Tex_DefaultTargetFormat='pdf'
635 let g:Tex_MultipleCompileFormats='pdf'
638 let g:sneak#streak = 1
639 let g:sneak#target_labels = "aoeuisnthdpylrcgfqjkxzmwvz" " dvorak
640 let g:sneak#use_ic_scs = 1 " follow 'ignorecase' and 'smartcase'
658 " Convenient command to see the difference between the current buffer and the
659 " file it was loaded from, thus the changes you made.
660 " Only define it when not defined already.
661 if !exists(":DiffOrig")
662 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
663 \ | wincmd p | diffthis
667 function! EditConfig(what)
668 let l:dir = split(&runtimepath,',')[0]
670 let l:file = expand($MYVIMRC)
671 elseif ! isdirectory(globpath(l:dir, a:what))
672 echoe a:what." is not valid!"
673 elseif empty(&filetype)
674 echoe 'filetype is empty!'
676 let l:file = l:dir.'/'.a:what.'/'.&filetype.'.vim'
679 execute ':vsplit '.file
682 nmap <leader>ev :call EditConfig('vimrc')<CR>
683 nmap <leader>ef :call EditConfig('ftplugin')<CR>
684 nmap <leader>es :call EditConfig('syntax')<CR>
685 nmap <leader>ei :call EditConfig('indent')<CR>
686 nmap <leader>eu :UltiSnipsEdit<CR>:lcd %:p:h<CR>
689 " http://tex.stackexchange.com/a/52932
690 let g:myLangList=["en_gb","en_us","de","fr"]
692 function! ToggleSpell()
693 if !exists("b:myLang")
696 execute "setlocal spell!"
698 echo "setlocal spelllang=" g:myLangList[b:myLang]
702 function! SwitchSpell()
703 if !exists("b:myLang")
707 let b:myLang=b:myLang+1
708 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
710 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
711 echo "setlocal spelllang=" g:myLangList[b:myLang]
714 nnoremap <silent> coS :call SwitchSpell()<CR>
715 " fix spelling with first choice
716 nnoremap <Leader>f 1z=
718 " gitdir or home {{{2
720 " http://git.io/v3GAV
721 function! FindGitDirOrHome()
722 let filedir = expand('%:p:h')
723 if isdirectory(filedir)
724 let cmd = 'bash -c "(cd ' . filedir . '; git rev-parse --show-toplevel 2>/dev/null)"'
725 let gitdir = system(cmd)
726 if strlen(gitdir) == 0
736 " vim:set et sw=2 ts=2 tw=78: