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'
54 " remove entries first
55 set runtimepath -=$HOME/.vim
56 set runtimepath -=$HOME/.vim/after
57 set runtimepath -=$XDG_CONFIG_HOME/vim
58 set runtimepath -=$XDG_CONFIG_HOME/vim/after
59 " then prepend and append them
60 set runtimepath ^=$XDG_CONFIG_HOME/vim
61 set runtimepath +=$XDG_CONFIG_HOME/vim/after
63 filetype plugin indent on
70 " moving around, searching and patterns {{{2
71 set incsearch " show match for partly typed search command
72 set ignorecase " ignore case when using a search pattern
73 set smartcase " override 'ignorecase' when pattern has upper case characters
74 set hlsearch " highlight all matches for the last used search pattern
76 set nostartofline " don't move the cursor to the first non-blank char of a line
77 set path=.,include/,../include/,/usr/include/c++/*,/opt/ros/hydro/include
79 " displaying text {{{2
80 set scrolloff=5 " number of screen lines to show around the cursor
81 set nowrap " long lines wrap
82 set linebreak " wrap long lines at a character in 'breakat'
83 set showbreak=↪ " show these chars for wrapped lines
85 set lazyredraw " don't redraw while executing macros
87 set list " show chars defined in 'listchars'
88 set listchars=tab:▸\ " list of strings used for list mode
89 set listchars+=extends:❯,precedes:❮
90 " Only shown when not in insert mode
93 au InsertEnter * :set listchars-=trail:·
94 au InsertLeave * :set listchars+=trail:·
97 set sidescroll=1 " number of collumns to scroll
98 set sidescrolloff=1 " don't scroll over the listchars
100 set fillchars=diff:⣿,vert:│
102 set nonumber " show the line number for each line
103 set norelativenumber " show the relative line number for each line
105 " syntax, highlighting and spelling {{{2
106 set synmaxcol=800 " don't highlight long lines
108 set dictionary=spell " list of dictionary files for keyword completion
112 " multiple windows {{{2
113 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
115 set previewheight=20 " default height for the preview window
119 " set splitbelow " a new window is put below of the current one
120 set splitright " a new window is put right of the current one
125 " using the mouse {{{2
126 set mouse=rnv " list of flags for using the mouse
127 set ttymouse=xterm " type of mouse
129 " messages and info {{{2
130 set showcmd " Show (partial) command in status line.
131 set ruler " show the cursor position all the time
132 set confirm " Ask what to do when closing unsaved documents
133 set shortmess=filnxtoOI " don't show intro message
136 set backspace=indent,eol,start " allow backspacing over everything in insert mode
138 set showmatch " Show matching brackets.
140 set nojoinspaces " don't use two spaces after '.' when joining a line
141 set formatoptions=jcrnql
143 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
145 set complete=.,w,b,u,t
146 " whether to use a popup menu for Insert mode completion
147 set completeopt=longest,menuone,preview
149 " tabs and indent {{{2
150 set shiftwidth=4 " number of spaces used for each step of (auto)indent
151 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
152 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
153 set shiftround " round to 'shiftwidth' for "<<" and ">>"
154 set expandtab " expand <Tab> to spaces in Insert mode
157 set pastetoggle=<F11> " key sequence to toggle paste mode
160 set foldmethod=marker " folding type
161 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
163 " save and restore folds
164 set viewoptions=folds,cursor " don't save local options
167 set diffopt=filler,vertical
169 " reading and writing files {{{2
170 set modeline " read modelines
171 set modelines=2 " only check first/last 2 lines
173 set writebackup " write a backup file before overwriting a file
174 set backup " keep a backup after owerwriting a file
175 set backupdir=$XDG_CACHE_HOME/vim/backup//
177 set backupskip+=.netrc " skip netrc
178 set backupskip+=/dev/shm/pass* " skip passwordstore files
180 set undofile " persistent undo history
181 set undodir=$XDG_CACHE_HOME/vim/undo//
185 au BufWritePre .netrc setlocal noundofile
186 au BufWritePre /dev/shm/pass* setlocal noundofile
187 au BufWritePre /tmp/* setlocal noundofile
190 set autowrite " automatically write a file when leaving a modified buffer
191 set autoread " automatically read a file that has been modified
195 set directory=$XDG_CACHE_HOME/vim/swap//
197 " command line editing {{{2
198 set history=5000 " how many command lines are remembered
199 set wildmenu " command-line completion shows a list of matches
200 set wildmode=longest:full,full " specifies how command line completion works
202 set wildignore+=.hg,.git,.svn " Version control
203 set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
204 set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
205 set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
206 set wildignore+=*.spl " compiled spelling word lists
207 set wildignore+=*.sw? " Vim swap files
208 set wildignore+=*.luac " Lua byte code
209 set wildignore+=*.pyc " Python byte code
210 set wildignore+=*.orig " Merge resolution files
213 set virtualedit=block " let cursor move past last char in <C-V> mode
214 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
216 set viewdir=$XDG_CACHE_HOME/vim/view//
219 " Resize splits when the window is resized {{{2
222 autocmd VimResized * :wincmd =
225 " Only show cursorline in the current window and in normal mode {{{2
228 au WinLeave,InsertEnter * set nocursorline
229 au WinEnter,InsertLeave * set cursorline
232 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
235 au StdinReadPost * :set buftype=nofile
238 " Jump to last known cursor position {{{2
241 " blacklist certain filetype
242 let blacklist = ['gitcommit']
243 autocmd BufReadPost *
244 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
245 \ exe "normal! g`\"" |
251 " allow both <space> and / to be <leader>
255 nnoremap <leader><cr> :make<cr>
258 nnoremap <silent> <Leader>/ :silent nohl<CR>
261 nnoremap <leader>[ :tabprev<cr>
262 nnoremap <leader>] :tabnext<cr>
265 nnoremap <leader>W :set wrap!<cr>
267 " paste from selection
268 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
269 " paste from clipboard
270 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
272 " Clean trailing whitespace
273 nnoremap <silent> <leader>ww m':%s/\s\+$//<cr>:let @/=''<cr>``zz
276 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
277 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
279 " jump to last cursor position
282 " Select (charwise) the contents of the current line, excluding indentation.
285 " Toggle [i]nvisible characters
286 nnoremap <leader>i :set list!<cr>
289 nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
292 nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
293 nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
300 " display the number of matches for the last search
301 nmap <Leader># :%s:<C-R>/::gn<CR>
303 " center cursor after search and open folds
307 " same when jumping around
310 nnoremap <c-o> <c-o>zzzv
312 " Not using the default mappings of 'To line from top/bottom'
318 " Heresy, emacs insert bindings
319 inoremap <c-a> <esc>I
320 inoremap <c-e> <esc>A
321 cnoremap <c-a> <home>
324 " proper movement when lines are wrapped
325 noremap <expr> j (v:count == 0 ? 'gj' : 'j')
326 noremap <expr> k (v:count == 0 ? 'gk' : 'k')
332 noremap <Right> <NOP>
334 inoremap <Down> <NOP>
335 inoremap <Left> <NOP>
336 inoremap <Right> <NOP>
338 cnoremap <Down> <NOP>
339 cnoremap <Left> <NOP>
340 cnoremap <Right> <NOP>
342 cnoremap <C-J> <Down>
343 cnoremap <C-H> <Left>
344 cnoremap <C-L> <Right>
346 " close all folds open fold in cursor
349 " edit vimrc in new tab
350 nmap <leader>ev :tabedit $MYVIMRC<CR>:lcd %:p:h<CR>
352 map <F1> :ls<CR>:b<space>
354 nnoremap <C-L> <C-W>w
355 nnoremap <C-H> <C-W>W
357 "xterm mouse with middleclick paste
358 nnoremap <MiddleMouse> i<MiddleMouse>
359 vnoremap <MiddleMouse> s<MiddleMouse>
361 " fix legacy vi inconsistency
364 " allow repeat operator on visual
365 vnoremap . :normal .<CR>
367 " add line without changing position or leaving mode
368 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
369 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
371 " Don't use Ex mode, use Q for formatting
374 " allow undoing in insert-mode
375 inoremap <C-U> <C-G>u<C-U>
376 inoremap <C-W> <C-G>u<C-W>
378 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
379 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
380 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
381 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
383 " space will toggle current fold in normal mode
384 nnoremap <leader><Space> za
385 " create folds around visual selection
386 vnoremap <leader><Space> zf
388 autocmd BufWinLeave *.* mkview
389 autocmd BufWinEnter *.* silent loadview
392 cnoremap w!! w !sudo tee % > /dev/null
396 let g:AgSmartCase = 1
397 nnoremap <leader>ag yiw:Ag
\12"<cr>
398 vnoremap <leader>ag y:Ag
\12"<cr>
401 let g:airline_detect_whitespace=2
402 let g:airline#extensions#tabline#enabled = 1
403 let g:airline_powerline_fonts = 1
406 let g:checkattach_filebrowser = 'ranger'
409 let delimitMate_expand_cr = 2
410 let g:delimitMate_expand_space = 1
413 nnoremap <silent> <Leader>ff :FSHere<CR>
414 nnoremap <silent> <Leader>fl :FSRight<CR>
415 nnoremap <silent> <Leader>fh :FSLeft<CR>
416 nnoremap <silent> <Leader>fL :FSSplitRight<CR>
417 nnoremap <silent> <Leader>fH :FSSplitLeft<CR>
420 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
421 " delete fugitive buffers when closed
422 autocmd BufReadPost fugitive://* set bufhidden=delete
424 nnoremap <silent> <leader>gs :Gstatus<CR>
425 nnoremap <silent> <leader>gd :Gdiff<CR>
426 nnoremap <silent> <leader>gc :tab Gcommit -v<CR>
427 nnoremap <silent> <leader>ga :Gwrite<cr>
428 nnoremap <silent> <leader>gb :Gblame<cr>
431 nnoremap <F7> :GundoToggle<CR>
434 let g:indent_guides_default_mapping = 0
435 let g:indent_guides_guide_size = 1
436 nmap <silent> cog <Plug>IndentGuidesToggle
437 nmap <silent> [og <Plug>IndentGuidesEnable
438 nmap <silent> ]og <Plug>IndentGuidesDisable
441 " open/close NERDTree with \e
442 nmap <Leader>e :NERDTreeToggle<CR>
443 nmap <F6> :NERDTreeToggle<CR>
444 " <space> to open files/dirs
445 let NERDTreeMapActivateNode='l'
446 " close vim if only NERDTree is open
447 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
451 let g:pymode_rope_completion = 0
452 let g:pymode_rope = 0
453 let g:pymode_folding = 1
454 let g:pymode_lint_ignore = "E221,E266,E501"
455 let g:pymode_syntax_space_errors = 0 " don't bother me when I'm typing
458 let g:syntastic_enable_highlighting = 0
459 let g:syntastic_error_symbol='E'
460 let g:syntastic_style_error_symbol='S'
461 let g:syntastic_warning_symbol='W'
462 let g:syntastic_style_warning_symbol='S'
463 let g:syntastic_always_populate_loc_list=1
464 nmap <silent> <leader>y :SyntasticCheck<cr>
467 let g:syntastic_check_on_open=1
471 map <F5> :TagbarToggle<cr>
472 let g:tagbar_sort = 0
473 let g:tagbar_compact = 1
474 let g:tagbar_autoshowtag = 1
475 let g:tagbar_width = 25
476 let g:tagbar_iconchars = ['+', '-']
479 let g:UltiSnipsEditSplit = 'vertical'
480 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
481 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
482 let g:UltiSnipsExpandTrigger = "<C-L>"
483 let g:UltiSnipsJumpForwardTrigger = "<C-L>"
484 let g:UltiSnipsJumpBackwardTrigger = "<C-H>"
487 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
488 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
489 let g:ycm_extra_conf_vim_data = ['getcwd()']
490 let g:ycm_add_preview_to_completeopt = 1
491 let g:ycm_autoclose_preview_window_after_insertion = 1
492 "let g:ycm_extra_conf_vim_data = ['%:p']
493 nnoremap <leader>jd :YcmCompleter GoTo<CR>
495 " vim-easy-align {{{2
496 " start interactive EasyAlign in visual mode
497 vmap <Enter> <Plug>(EasyAlign)
500 let g:vim_json_syntax_conceal = 0
503 let g:tex_flavor='latex'
504 let g:Tex_DefaultTargetFormat='pdf'
505 let g:Tex_MultipleCompileFormats='pdf'
510 " Convenient command to see the difference between the current buffer and the
511 " file it was loaded from, thus the changes you made.
512 " Only define it when not defined already.
513 if !exists(":DiffOrig")
514 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
515 \ | wincmd p | diffthis
519 " http://tex.stackexchange.com/a/52932
520 let g:myLangList=["en_gb","en_us","de","fr"]
522 function! ToggleSpell()
523 if !exists("b:myLang")
526 execute "setlocal spell!"
528 echo "setlocal spelllang=" g:myLangList[b:myLang]
532 function! SwitchSpell()
533 if !exists("b:myLang")
537 let b:myLang=b:myLang+1
538 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
540 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
541 echo "setlocal spelllang=" g:myLangList[b:myLang]
544 nnoremap <silent> <Leader>s :call ToggleSpell()<CR>
545 nnoremap <silent> <Leader>S :call SwitchSpell()<CR>
546 " fix spelling with first choice
547 nnoremap <Leader>f 1z=