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'
30 Plugin 'scrooloose/nerdtree'
31 Plugin 'scrooloose/syntastic'
32 Plugin 'sjl/gundo.vim'
33 Plugin 'tomtom/tcomment_vim'
34 Plugin 'tpope/vim-endwise'
35 Plugin 'tpope/vim-fugitive'
36 Plugin 'tpope/vim-repeat'
37 Plugin 'tpope/vim-surround'
38 Plugin 'tpope/vim-unimpaired'
39 Plugin 'valloric/youcompleteme'
40 Plugin 'vim-scripts/yankring.vim'
43 Plugin 'sirver/ultisnips'
44 Plugin 'honza/vim-snippets'
47 Plugin 'ompugao/ros.vim'
48 Plugin 'ompugao/ctrlp-ros'
50 " seems to have problems right now... may be add later?
51 " Plugin 'jalcine/cmake.vim'
52 " Plugin 'powerman/vim-plugin-viewdoc'
55 Plugin 'http://git.code.sf.net/p/vim-latex/vim-latex'
56 " Plugin 'lokaltog/vim-easymotion'
57 Plugin 'justinmk/vim-sneak'
58 Plugin 'chrisbra/checkattach'
59 Plugin 'nathanaelkane/vim-indent-guides'
61 " remove entries first
62 set runtimepath -=$HOME/.vim
63 set runtimepath -=$HOME/.vim/after
64 set runtimepath -=$XDG_CONFIG_HOME/vim
65 set runtimepath -=$XDG_CONFIG_HOME/vim/after
66 " then prepend and append them
67 set runtimepath ^=$XDG_CONFIG_HOME/vim
68 set runtimepath +=$XDG_CONFIG_HOME/vim/after
70 filetype plugin indent on
77 " moving around, searching and patterns {{{2
78 set incsearch " show match for partly typed search command
79 set ignorecase " ignore case when using a search pattern
80 set smartcase " override 'ignorecase' when pattern has upper case characters
81 set hlsearch " highlight all matches for the last used search pattern
83 set nostartofline " don't move the cursor to the first non-blank char of a line
84 set path=.,include/,../include/,/usr/include/c++/*,/opt/ros/hydro/include
86 " displaying text {{{2
87 set scrolloff=5 " number of screen lines to show around the cursor
88 set nowrap " long lines wrap
89 set linebreak " wrap long lines at a character in 'breakat'
90 set showbreak=↪ " show these chars for wrapped lines
92 set lazyredraw " don't redraw while executing macros
94 set list " show chars defined in 'listchars'
95 set listchars=tab:▸\ " list of strings used for list mode
96 set listchars+=extends:❯,precedes:❮
97 " Only shown when not in insert mode
100 au InsertEnter * :set listchars-=trail:·
101 au InsertLeave * :set listchars+=trail:·
104 set sidescroll=1 " number of collumns to scroll
105 set sidescrolloff=1 " don't scroll over the listchars
107 set fillchars=diff:⣿,vert:│
109 set nonumber " show the line number for each line
110 set norelativenumber " show the relative line number for each line
112 " syntax, highlighting and spelling {{{2
113 set synmaxcol=800 " don't highlight long lines
115 set dictionary=spell " list of dictionary files for keyword completion
119 " multiple windows {{{2
120 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
122 set previewheight=20 " default height for the preview window
126 " set splitbelow " a new window is put below of the current one
127 set splitright " a new window is put right of the current one
132 " using the mouse {{{2
133 set mouse=rnv " list of flags for using the mouse
134 set ttymouse=xterm " type of mouse
136 " messages and info {{{2
137 set showcmd " Show (partial) command in status line.
138 set ruler " show the cursor position all the time
139 set confirm " Ask what to do when closing unsaved documents
140 set shortmess=filnxtoOI " don't show intro message
143 set backspace=indent,eol,start " allow backspacing over everything in insert mode
145 set showmatch " Show matching brackets.
147 set nojoinspaces " don't use two spaces after '.' when joining a line
148 set formatoptions=jcrnql
150 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
152 set complete=.,w,b,u,t
153 " whether to use a popup menu for Insert mode completion
154 set completeopt=longest,menuone,preview
156 " tabs and indent {{{2
157 set shiftwidth=4 " number of spaces used for each step of (auto)indent
158 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
159 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
160 set shiftround " round to 'shiftwidth' for "<<" and ">>"
161 set expandtab " expand <Tab> to spaces in Insert mode
164 set pastetoggle=<F11> " key sequence to toggle paste mode
167 set foldmethod=marker " folding type
168 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
170 " save and restore folds
171 set viewoptions=folds,cursor " don't save local options
174 set diffopt=filler,vertical
176 " reading and writing files {{{2
177 set modeline " read modelines
178 set modelines=2 " only check first/last 2 lines
180 set writebackup " write a backup file before overwriting a file
181 set backup " keep a backup after owerwriting a file
182 set backupdir=$XDG_CACHE_HOME/vim/backup//
184 set backupskip+=.netrc " skip netrc
185 set backupskip+=/dev/shm/pass* " skip passwordstore files
187 set undofile " persistent undo history
188 set undodir=$XDG_CACHE_HOME/vim/undo//
192 au BufWritePre .netrc setlocal noundofile
193 au BufWritePre /dev/shm/pass* setlocal noundofile
194 au BufWritePre /tmp/* setlocal noundofile
197 set autowrite " automatically write a file when leaving a modified buffer
198 set autoread " automatically read a file that has been modified
202 set directory=$XDG_CACHE_HOME/vim/swap//
204 " command line editing {{{2
205 set history=5000 " how many command lines are remembered
206 set wildmenu " command-line completion shows a list of matches
207 set wildmode=longest:full,full " specifies how command line completion works
209 set wildignore+=.hg,.git,.svn " Version control
210 set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
211 set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
212 set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
213 set wildignore+=*.spl " compiled spelling word lists
214 set wildignore+=*.sw? " Vim swap files
215 set wildignore+=*.luac " Lua byte code
216 set wildignore+=*.pyc " Python byte code
217 set wildignore+=*.orig " Merge resolution files
220 set virtualedit=block " let cursor move past last char in <C-V> mode
221 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
223 set viewdir=$XDG_CACHE_HOME/vim/view//
226 " Resize splits when the window is resized {{{2
229 autocmd VimResized * :wincmd =
232 " Only show cursorline in the current window and in normal mode {{{2
235 au WinLeave,InsertEnter * set nocursorline
236 au WinEnter,InsertLeave * set cursorline
239 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
242 au StdinReadPost * :set buftype=nofile
245 " Jump to last known cursor position {{{2
248 " blacklist certain filetype
249 let blacklist = ['gitcommit']
250 autocmd BufReadPost *
251 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
252 \ exe "normal! g`\"" |
258 " allow both <space> and / to be <leader>
262 nnoremap <leader>r :make<cr>
263 nnoremap <leader><cr> :make<cr>
266 nnoremap <silent> <Leader>/ :silent nohl<CR>
269 nnoremap <leader>[ :tabprev<cr>
270 nnoremap <leader>] :tabnext<cr>
272 " paste from selection
273 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
274 " paste from clipboard
275 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
277 " Clean trailing whitespace
278 nnoremap <silent> <leader>ww m':%s/\s\+$//<cr>:let @/=''<cr>``zz
281 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
282 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
284 " jump to last cursor position
287 " Select (charwise) the contents of the current line, excluding indentation.
291 nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
294 " nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
295 " nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
302 " display the number of matches for the last search
303 nmap <Leader># :%s:<C-R>/::gn<CR>
305 " center cursor after search and open folds
309 " same when jumping around
312 nnoremap <c-o> <c-o>zzzv
314 " Not using the default mappings of 'To line from top/bottom'
320 " Heresy, emacs insert bindings
321 inoremap <c-a> <esc>I
322 inoremap <c-e> <esc>A
323 cnoremap <c-a> <home>
326 " proper movement when lines are wrapped
327 noremap <expr> j (v:count == 0 ? 'gj' : 'j')
328 noremap <expr> k (v:count == 0 ? 'gk' : 'k')
334 noremap <Right> <NOP>
336 inoremap <Down> <NOP>
337 inoremap <Left> <NOP>
338 inoremap <Right> <NOP>
340 cnoremap <Down> <NOP>
341 cnoremap <Left> <NOP>
342 cnoremap <Right> <NOP>
344 cnoremap <C-J> <Down>
345 cnoremap <C-H> <Left>
346 cnoremap <C-L> <Right>
348 " close all folds open fold in cursor
351 " edit vimrc in new tab
352 nmap <leader>ev :tabedit $MYVIMRC<CR>:lcd %:p:h<CR>
354 map <F1> :ls<CR>:b<space>
356 nnoremap <C-L> <C-W>w
357 nnoremap <C-H> <C-W>W
359 "xterm mouse with middleclick paste
360 nnoremap <MiddleMouse> i<MiddleMouse>
361 vnoremap <MiddleMouse> s<MiddleMouse>
363 " fix legacy vi inconsistency
366 " allow repeat operator on visual
367 vnoremap . :normal .<CR>
369 " add line without changing position or leaving mode
370 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
371 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
373 " Don't use Ex mode, use Q for formatting
376 " break undo sequence before removing word
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
395 " uppercase previous word
396 inoremap <C-C> <Esc>gUiwgi
398 " plugins options {{{1
400 let g:AgSmartCase = 1
401 nnoremap <leader>ag yiw:Ag
\12"<cr>
402 vnoremap <leader>ag y:Ag
\12"<cr>
405 let g:airline#extensions#whitespace#enabled = 1
406 let g:airline#extensions#tabline#enabled = 1
407 let g:airline_powerline_fonts = 1
410 let g:checkattach_filebrowser = 'ranger'
411 let g:checkattach_once = 'y'
414 let delimitMate_expand_cr = 2
415 let g:delimitMate_expand_space = 1
418 nnoremap <silent> <Leader>ff :FSHere<CR>
419 nnoremap <silent> <Leader>fl :FSRight<CR>
420 nnoremap <silent> <Leader>fh :FSLeft<CR>
421 nnoremap <silent> <Leader>fL :FSSplitRight<CR>
422 nnoremap <silent> <Leader>fH :FSSplitLeft<CR>
425 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
426 " delete fugitive buffers when closed
427 autocmd BufReadPost fugitive://* set bufhidden=delete
429 nnoremap <silent> <leader>gs :Gstatus<CR>
430 nnoremap <silent> <leader>gd :Gdiff<CR>
431 nnoremap <silent> <leader>gc :tab Gcommit -v<CR>
432 nnoremap <silent> <leader>ga :Gwrite<cr>
433 nnoremap <silent> <leader>gb :Gblame<cr>
436 nnoremap <F7> :GundoToggle<CR>
439 let g:indent_guides_default_mapping = 0
440 let g:indent_guides_guide_size = 1
441 nmap <silent> cog <Plug>IndentGuidesToggle
442 nmap <silent> [og <Plug>IndentGuidesEnable
443 nmap <silent> ]og <Plug>IndentGuidesDisable
446 " open/close NERDTree with \e
447 nmap <Leader>e :NERDTreeToggle<CR>
448 nmap <F6> :NERDTreeToggle<CR>
449 " <space> to open files/dirs
450 let NERDTreeMapActivateNode='l'
451 " close vim if only NERDTree is open
452 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
456 let g:pymode_rope_completion = 0
457 let g:pymode_rope = 0
458 let g:pymode_folding = 1
459 let g:pymode_lint_ignore = "E221,E266,E501"
460 let g:pymode_syntax_space_errors = 0 " don't bother me when I'm typing
463 let g:syntastic_enable_highlighting = 0
464 let g:syntastic_error_symbol='E'
465 let g:syntastic_style_error_symbol='S'
466 let g:syntastic_warning_symbol='W'
467 let g:syntastic_style_warning_symbol='S'
468 let g:syntastic_always_populate_loc_list=1
469 nmap <silent> <leader>y :SyntasticCheck<cr>
472 let g:syntastic_check_on_open=1
476 map <F5> :TagbarToggle<cr>
477 let g:tagbar_sort = 0
478 let g:tagbar_compact = 1
479 let g:tagbar_autoshowtag = 1
480 let g:tagbar_width = 25
481 let g:tagbar_iconchars = ['+', '-']
484 let g:UltiSnipsEditSplit = 'vertical'
485 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
486 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
487 let g:UltiSnipsExpandTrigger = "<tab>"
488 let g:UltiSnipsJumpForwardTrigger = "<tab>"
489 let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
491 " UltiSnips completion function that tries to expand a snippet. If there's no
492 " snippet for expanding, it checks for completion window and if it's shown,
493 " selects first element. If there's no completion window it tries to jump to
494 " next placeholder. If there's no placeholder it just returns TAB key
495 " https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-15451411
496 function! g:UltiSnips_Complete()
497 call UltiSnips#ExpandSnippet()
498 if g:ulti_expand_res == 0
502 call UltiSnips#JumpForwards()
503 if g:ulti_jump_forwards_res == 0
510 au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
511 let g:UltiSnipsListSnippets="<c-e>"
514 nnoremap <silent> <leader>p :YRShow<cr>
515 let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
516 let g:yankring_replace_n_pkey = ''
517 let g:yankring_replace_n_nkey = ''
519 " map Y to y$ for the yank ring
520 function! YRRunAfterMaps()
521 nnoremap Y :<C-U>YRYankCount 'y$'<CR>
525 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
526 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
527 let g:ycm_extra_conf_vim_data = ['getcwd()']
528 let g:ycm_add_preview_to_completeopt = 1
529 let g:ycm_autoclose_preview_window_after_insertion = 1
530 "let g:ycm_extra_conf_vim_data = ['%:p']
531 nnoremap <leader>jd :YcmCompleter GoTo<CR>
533 " vim-easy-align {{{2
534 " start interactive EasyAlign in visual mode
535 vmap <Enter> <Plug>(EasyAlign)
538 let g:vim_json_syntax_conceal = 0
541 let g:tex_flavor='latex'
542 let g:Tex_DefaultTargetFormat='pdf'
543 let g:Tex_MultipleCompileFormats='pdf'
546 let g:sneak#streak = 1
547 let g:sneak#target_labels = "aoeuisnthdpylrcgfqjkxzmwvz" " dvorak
548 let g:sneak#use_ic_scs = 1 " follow 'ignorecase' and 'smartcase'
566 " Convenient command to see the difference between the current buffer and the
567 " file it was loaded from, thus the changes you made.
568 " Only define it when not defined already.
569 if !exists(":DiffOrig")
570 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
571 \ | wincmd p | diffthis
575 " http://tex.stackexchange.com/a/52932
576 let g:myLangList=["en_gb","en_us","de","fr"]
578 function! ToggleSpell()
579 if !exists("b:myLang")
582 execute "setlocal spell!"
584 echo "setlocal spelllang=" g:myLangList[b:myLang]
588 function! SwitchSpell()
589 if !exists("b:myLang")
593 let b:myLang=b:myLang+1
594 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
596 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
597 echo "setlocal spelllang=" g:myLangList[b:myLang]
600 nnoremap <silent> coS :call SwitchSpell()<CR>
601 " fix spelling with first choice
602 nnoremap <Leader>f 1z=