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 'elzr/vim-json'
20 Plugin 'http://git.code.sf.net/p/vim-latex/vim-latex'
21 Plugin 'junegunn/vim-easy-align'
22 Plugin 'kien/ctrlp.vim'
23 Plugin 'kshenoy/vim-signature'
24 Plugin 'majutsushi/tagbar'
26 Plugin 'scrooloose/nerdtree'
27 Plugin 'scrooloose/syntastic'
28 Plugin 'sirver/ultisnips'
29 Plugin 'sjl/gundo.vim'
30 Plugin 'tomtom/tcomment_vim'
31 Plugin 'tpope/vim-fugitive'
32 Plugin 'tpope/vim-repeat'
33 Plugin 'tpope/vim-surround'
34 Plugin 'tpope/vim-unimpaired'
35 Plugin 'valloric/youcompleteme'
37 Plugin 'ompugao/ros.vim'
38 Plugin 'ompugao/ctrlp-ros'
40 Plugin 'firef0x/pkgbuild.vim'
41 Plugin 'derekwyatt/vim-fswitch'
42 " seems to have problems right now... may be add later?
43 " Plugin 'jalcine/cmake.vim'
44 " Plugin 'powerman/vim-plugin-viewdoc'
46 " endwise needs to be after delimitmate
47 Plugin 'raimondi/delimitmate'
48 Plugin 'tpope/vim-endwise'
49 Plugin 'lokaltog/vim-easymotion'
50 Plugin 'chrisbra/checkattach'
51 Plugin 'klen/python-mode'
52 Plugin 'nathanaelkane/vim-indent-guides'
53 Plugin 'vim-scripts/yankring.vim'
55 " remove entries first
56 set runtimepath -=$HOME/.vim
57 set runtimepath -=$HOME/.vim/after
58 set runtimepath -=$XDG_CONFIG_HOME/vim
59 set runtimepath -=$XDG_CONFIG_HOME/vim/after
60 " then prepend and append them
61 set runtimepath ^=$XDG_CONFIG_HOME/vim
62 set runtimepath +=$XDG_CONFIG_HOME/vim/after
64 filetype plugin indent on
71 " moving around, searching and patterns {{{2
72 set incsearch " show match for partly typed search command
73 set ignorecase " ignore case when using a search pattern
74 set smartcase " override 'ignorecase' when pattern has upper case characters
75 set hlsearch " highlight all matches for the last used search pattern
77 set nostartofline " don't move the cursor to the first non-blank char of a line
78 set path=.,include/,../include/,/usr/include/c++/*,/opt/ros/hydro/include
80 " displaying text {{{2
81 set scrolloff=5 " number of screen lines to show around the cursor
82 set nowrap " long lines wrap
83 set linebreak " wrap long lines at a character in 'breakat'
84 set showbreak=↪ " show these chars for wrapped lines
86 set lazyredraw " don't redraw while executing macros
88 set list " show chars defined in 'listchars'
89 set listchars=tab:▸\ " list of strings used for list mode
90 set listchars+=extends:❯,precedes:❮
91 " Only shown when not in insert mode
94 au InsertEnter * :set listchars-=trail:·
95 au InsertLeave * :set listchars+=trail:·
98 set sidescroll=1 " number of collumns to scroll
99 set sidescrolloff=1 " don't scroll over the listchars
101 set fillchars=diff:⣿,vert:│
103 set nonumber " show the line number for each line
104 set norelativenumber " show the relative line number for each line
106 " syntax, highlighting and spelling {{{2
107 set synmaxcol=800 " don't highlight long lines
109 set dictionary=spell " list of dictionary files for keyword completion
113 " multiple windows {{{2
114 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
116 set previewheight=20 " default height for the preview window
120 " set splitbelow " a new window is put below of the current one
121 set splitright " a new window is put right of the current one
126 " using the mouse {{{2
127 set mouse=rnv " list of flags for using the mouse
128 set ttymouse=xterm " type of mouse
130 " messages and info {{{2
131 set showcmd " Show (partial) command in status line.
132 set ruler " show the cursor position all the time
133 set confirm " Ask what to do when closing unsaved documents
134 set shortmess=filnxtoOI " don't show intro message
137 set backspace=indent,eol,start " allow backspacing over everything in insert mode
139 set showmatch " Show matching brackets.
141 set nojoinspaces " don't use two spaces after '.' when joining a line
142 set formatoptions=jcrnql
144 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
146 set complete=.,w,b,u,t
147 " whether to use a popup menu for Insert mode completion
148 set completeopt=longest,menuone,preview
150 " tabs and indent {{{2
151 set shiftwidth=4 " number of spaces used for each step of (auto)indent
152 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
153 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
154 set shiftround " round to 'shiftwidth' for "<<" and ">>"
155 set expandtab " expand <Tab> to spaces in Insert mode
158 set pastetoggle=<F11> " key sequence to toggle paste mode
161 set foldmethod=marker " folding type
162 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
164 " save and restore folds
165 set viewoptions=folds,cursor " don't save local options
168 set diffopt=filler,vertical
170 " reading and writing files {{{2
171 set modeline " read modelines
172 set modelines=2 " only check first/last 2 lines
174 set writebackup " write a backup file before overwriting a file
175 set backup " keep a backup after owerwriting a file
176 set backupdir=$XDG_CACHE_HOME/vim/backup//
178 set backupskip+=.netrc " skip netrc
179 set backupskip+=/dev/shm/pass* " skip passwordstore files
181 set undofile " persistent undo history
182 set undodir=$XDG_CACHE_HOME/vim/undo//
186 au BufWritePre .netrc setlocal noundofile
187 au BufWritePre /dev/shm/pass* setlocal noundofile
188 au BufWritePre /tmp/* setlocal noundofile
191 set autowrite " automatically write a file when leaving a modified buffer
192 set autoread " automatically read a file that has been modified
196 set directory=$XDG_CACHE_HOME/vim/swap//
198 " command line editing {{{2
199 set history=5000 " how many command lines are remembered
200 set wildmenu " command-line completion shows a list of matches
201 set wildmode=longest:full,full " specifies how command line completion works
203 set wildignore+=.hg,.git,.svn " Version control
204 set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
205 set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
206 set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
207 set wildignore+=*.spl " compiled spelling word lists
208 set wildignore+=*.sw? " Vim swap files
209 set wildignore+=*.luac " Lua byte code
210 set wildignore+=*.pyc " Python byte code
211 set wildignore+=*.orig " Merge resolution files
214 set virtualedit=block " let cursor move past last char in <C-V> mode
215 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
217 set viewdir=$XDG_CACHE_HOME/vim/view//
220 " Resize splits when the window is resized {{{2
223 autocmd VimResized * :wincmd =
226 " Only show cursorline in the current window and in normal mode {{{2
229 au WinLeave,InsertEnter * set nocursorline
230 au WinEnter,InsertLeave * set cursorline
233 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
236 au StdinReadPost * :set buftype=nofile
239 " Jump to last known cursor position {{{2
242 " blacklist certain filetype
243 let blacklist = ['gitcommit']
244 autocmd BufReadPost *
245 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
246 \ exe "normal! g`\"" |
252 " allow both <space> and / to be <leader>
256 nnoremap <leader><cr> :make<cr>
259 nnoremap <silent> <Leader>/ :silent nohl<CR>
262 nnoremap <leader>[ :tabprev<cr>
263 nnoremap <leader>] :tabnext<cr>
266 nnoremap <leader>W :set wrap!<cr>
268 " paste from selection
269 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
270 " paste from clipboard
271 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
273 " Clean trailing whitespace
274 nnoremap <silent> <leader>ww m':%s/\s\+$//<cr>:let @/=''<cr>``zz
277 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
278 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
280 " jump to last cursor position
283 " Select (charwise) the contents of the current line, excluding indentation.
286 " Toggle [i]nvisible characters
287 nnoremap <leader>i :set list!<cr>
290 nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
293 nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
294 nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
301 " display the number of matches for the last search
302 nmap <Leader># :%s:<C-R>/::gn<CR>
304 " center cursor after search and open folds
308 " same when jumping around
311 nnoremap <c-o> <c-o>zzzv
313 " Not using the default mappings of 'To line from top/bottom'
319 " Heresy, emacs insert bindings
320 inoremap <c-a> <esc>I
321 inoremap <c-e> <esc>A
322 cnoremap <c-a> <home>
325 " proper movement when lines are wrapped
326 noremap <expr> j (v:count == 0 ? 'gj' : 'j')
327 noremap <expr> k (v:count == 0 ? 'gk' : 'k')
333 noremap <Right> <NOP>
335 inoremap <Down> <NOP>
336 inoremap <Left> <NOP>
337 inoremap <Right> <NOP>
339 cnoremap <Down> <NOP>
340 cnoremap <Left> <NOP>
341 cnoremap <Right> <NOP>
343 cnoremap <C-J> <Down>
344 cnoremap <C-H> <Left>
345 cnoremap <C-L> <Right>
347 " close all folds open fold in cursor
350 " edit vimrc in new tab
351 nmap <leader>ev :tabedit $MYVIMRC<CR>:lcd %:p:h<CR>
353 map <F1> :ls<CR>:b<space>
355 nnoremap <C-L> <C-W>w
356 nnoremap <C-H> <C-W>W
358 "xterm mouse with middleclick paste
359 nnoremap <MiddleMouse> i<MiddleMouse>
360 vnoremap <MiddleMouse> s<MiddleMouse>
362 " fix legacy vi inconsistency
365 " allow repeat operator on visual
366 vnoremap . :normal .<CR>
368 " add line without changing position or leaving mode
369 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
370 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
372 " Don't use Ex mode, use Q for formatting
375 " allow undoing in insert-mode
376 inoremap <C-U> <C-G>u<C-U>
377 inoremap <C-W> <C-G>u<C-W>
379 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
380 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
381 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
382 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
384 " space will toggle current fold in normal mode
385 nnoremap <leader><Space> za
386 " create folds around visual selection
387 vnoremap <leader><Space> zf
389 autocmd BufWinLeave *.* mkview
390 autocmd BufWinEnter *.* silent loadview
393 cnoremap w!! w !sudo tee % > /dev/null
397 let g:AgSmartCase = 1
398 nnoremap <leader>ag yiw:Ag
\12"<cr>
399 vnoremap <leader>ag y:Ag
\12"<cr>
402 let g:airline_detect_whitespace=2
403 let g:airline#extensions#tabline#enabled = 1
404 let g:airline_powerline_fonts = 1
407 let g:checkattach_filebrowser = 'ranger'
410 let delimitMate_expand_cr = 2
411 let g:delimitMate_expand_space = 1
414 nnoremap <silent> <Leader>ff :FSHere<CR>
415 nnoremap <silent> <Leader>fl :FSRight<CR>
416 nnoremap <silent> <Leader>fh :FSLeft<CR>
417 nnoremap <silent> <Leader>fL :FSSplitRight<CR>
418 nnoremap <silent> <Leader>fH :FSSplitLeft<CR>
421 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
422 " delete fugitive buffers when closed
423 autocmd BufReadPost fugitive://* set bufhidden=delete
425 nnoremap <silent> <leader>gs :Gstatus<CR>
426 nnoremap <silent> <leader>gd :Gdiff<CR>
427 nnoremap <silent> <leader>gc :tab Gcommit -v<CR>
428 nnoremap <silent> <leader>ga :Gwrite<cr>
429 nnoremap <silent> <leader>gb :Gblame<cr>
432 nnoremap <F7> :GundoToggle<CR>
435 let g:indent_guides_default_mapping = 0
436 let g:indent_guides_guide_size = 1
437 nmap <silent> cog <Plug>IndentGuidesToggle
438 nmap <silent> [og <Plug>IndentGuidesEnable
439 nmap <silent> ]og <Plug>IndentGuidesDisable
442 " open/close NERDTree with \e
443 nmap <Leader>e :NERDTreeToggle<CR>
444 nmap <F6> :NERDTreeToggle<CR>
445 " <space> to open files/dirs
446 let NERDTreeMapActivateNode='l'
447 " close vim if only NERDTree is open
448 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
452 let g:pymode_rope_completion = 0
453 let g:pymode_rope = 0
454 let g:pymode_folding = 1
455 let g:pymode_lint_ignore = "E221,E266,E501"
456 let g:pymode_syntax_space_errors = 0 " don't bother me when I'm typing
459 let g:syntastic_enable_highlighting = 0
460 let g:syntastic_error_symbol='E'
461 let g:syntastic_style_error_symbol='S'
462 let g:syntastic_warning_symbol='W'
463 let g:syntastic_style_warning_symbol='S'
464 let g:syntastic_always_populate_loc_list=1
465 nmap <silent> <leader>y :SyntasticCheck<cr>
468 let g:syntastic_check_on_open=1
472 map <F5> :TagbarToggle<cr>
473 let g:tagbar_sort = 0
474 let g:tagbar_compact = 1
475 let g:tagbar_autoshowtag = 1
476 let g:tagbar_width = 25
477 let g:tagbar_iconchars = ['+', '-']
480 let g:UltiSnipsEditSplit = 'vertical'
481 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
482 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
483 let g:UltiSnipsExpandTrigger = "<C-L>"
484 let g:UltiSnipsJumpForwardTrigger = "<C-L>"
485 let g:UltiSnipsJumpBackwardTrigger = "<C-H>"
488 nnoremap <silent> <leader>p :YRShow<cr>
489 let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
490 let g:yankring_replace_n_pkey = ''
491 let g:yankring_replace_n_nkey = ''
493 " map Y to y$ for the yank ring
494 function! YRRunAfterMaps()
495 nnoremap Y :<C-U>YRYankCount 'y$'<CR>
499 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
500 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
501 let g:ycm_extra_conf_vim_data = ['getcwd()']
502 let g:ycm_add_preview_to_completeopt = 1
503 let g:ycm_autoclose_preview_window_after_insertion = 1
504 "let g:ycm_extra_conf_vim_data = ['%:p']
505 nnoremap <leader>jd :YcmCompleter GoTo<CR>
507 " vim-easy-align {{{2
508 " start interactive EasyAlign in visual mode
509 vmap <Enter> <Plug>(EasyAlign)
512 let g:vim_json_syntax_conceal = 0
515 let g:tex_flavor='latex'
516 let g:Tex_DefaultTargetFormat='pdf'
517 let g:Tex_MultipleCompileFormats='pdf'
522 " Convenient command to see the difference between the current buffer and the
523 " file it was loaded from, thus the changes you made.
524 " Only define it when not defined already.
525 if !exists(":DiffOrig")
526 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
527 \ | wincmd p | diffthis
531 " http://tex.stackexchange.com/a/52932
532 let g:myLangList=["en_gb","en_us","de","fr"]
534 function! ToggleSpell()
535 if !exists("b:myLang")
538 execute "setlocal spell!"
540 echo "setlocal spelllang=" g:myLangList[b:myLang]
544 function! SwitchSpell()
545 if !exists("b:myLang")
549 let b:myLang=b:myLang+1
550 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
552 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
553 echo "setlocal spelllang=" g:myLangList[b:myLang]
556 nnoremap <silent> <Leader>s :call ToggleSpell()<CR>
557 nnoremap <silent> <Leader>S :call SwitchSpell()<CR>
558 " fix spelling with first choice
559 nnoremap <Leader>f 1z=