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 'bling/vim-airline'
18 Plugin 'elzr/vim-json'
20 Plugin 'http://git.code.sf.net/p/vim-latex/vim-latex'
21 Plugin 'kien/ctrlp.vim'
22 Plugin 'kshenoy/vim-signature'
23 Plugin 'majutsushi/tagbar'
24 Plugin 'scrooloose/nerdtree'
25 Plugin 'scrooloose/syntastic'
26 Plugin 'sjl/gundo.vim'
27 Plugin 'tomtom/tcomment_vim'
28 Plugin 'tpope/vim-endwise'
29 Plugin 'tpope/vim-fugitive'
30 Plugin 'tpope/vim-repeat'
31 Plugin 'tpope/vim-surround'
32 Plugin 'tpope/vim-unimpaired'
33 Plugin 'valloric/youcompleteme'
35 Plugin 'ompugao/ros.vim'
36 Plugin 'ompugao/ctrlp-ros'
38 Plugin 'firef0x/pkgbuild.vim'
39 Plugin 'derekwyatt/vim-fswitch'
40 " seems to have problems right now... may be add later?
41 " Plugin 'jalcine/cmake.vim'
42 " Plugin 'powerman/vim-plugin-viewdoc'
44 Plugin 'airblade/vim-gitgutter'
45 Plugin 'Raimondi/delimitMate'
46 Plugin 'SirVer/ultisnips'
47 Plugin 'Lokaltog/vim-easymotion'
49 " remove entries first
50 set runtimepath -=$HOME/.vim
51 set runtimepath -=$HOME/.vim/after
52 set runtimepath -=$XDG_CONFIG_HOME/vim
53 set runtimepath -=$XDG_CONFIG_HOME/vim/after
54 " then prepend and append them
55 set runtimepath ^=$XDG_CONFIG_HOME/vim
56 set runtimepath +=$XDG_CONFIG_HOME/vim/after
58 filetype plugin indent on
65 " moving around, searching and patterns {{{2
66 set incsearch " show match for partly typed search command
67 set ignorecase " ignore case when using a search pattern
68 set smartcase " override 'ignorecase' when pattern has upper case characters
69 set hlsearch " highlight all matches for the last used search pattern
71 set nostartofline " don't move the cursor to the first non-blank char of a line
72 set path=.,include/,../include/,/usr/include/c++/*,/opt/ros/hydro/include
74 " displaying text {{{2
75 set scrolloff=5 " number of screen lines to show around the cursor
76 set nowrap " long lines wrap
77 set linebreak " wrap long lines at a character in 'breakat'
78 set showbreak=↪ " show these chars for wrapped lines
80 set lazyredraw " don't redraw while executing macros
82 set list " show chars defined in 'listchars'
83 set listchars=tab:▸\ " list of strings used for list mode
84 set listchars+=extends:❯,precedes:❮
85 " Only shown when not in insert mode
88 au InsertEnter * :set listchars-=trail:·
89 au InsertLeave * :set listchars+=trail:·
92 set sidescroll=1 " number of collumns to scroll
93 set sidescrolloff=1 " don't scroll over the listchars
95 set fillchars=diff:⣿,vert:│
97 set nonumber " show the line number for each line
98 set norelativenumber " show the relative line number for each line
100 " syntax, highlighting and spelling {{{2
101 set synmaxcol=800 " don't highlight long lines
103 set dictionary=spell " list of dictionary files for keyword completion
107 " multiple windows {{{2
108 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
110 set previewheight=20 " default height for the preview window
114 " set splitbelow " a new window is put below of the current one
115 set splitright " a new window is put right of the current one
120 " using the mouse {{{2
121 set mouse=rnv " list of flags for using the mouse
122 set ttymouse=xterm " type of mouse
124 " messages and info {{{2
125 set showcmd " Show (partial) command in status line.
126 set ruler " show the cursor position all the time
127 set confirm " Ask what to do when closing unsaved documents
128 set shortmess=filnxtoOI " don't show intro message
131 set backspace=indent,eol,start " allow backspacing over everything in insert mode
133 set showmatch " Show matching brackets.
135 set nojoinspaces " don't use two spaces after '.' when joining a line
136 set formatoptions=jcrnql
138 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
140 set complete=.,w,b,u,t
141 " whether to use a popup menu for Insert mode completion
142 set completeopt=longest,menuone,preview
144 " tabs and indent {{{2
145 set shiftwidth=4 " number of spaces used for each step of (auto)indent
146 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
147 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
148 set shiftround " round to 'shiftwidth' for "<<" and ">>"
149 set expandtab " expand <Tab> to spaces in Insert mode
152 set pastetoggle=<F11> " key sequence to toggle paste mode
155 set foldmethod=marker " folding type
156 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
158 " save and restore folds
159 set viewoptions=folds,cursor " don't save local options
161 " reading and writing files {{{2
162 set modeline " read modelines
163 set modelines=2 " only check first/last 2 lines
164 set writebackup " write a backup file before overwriting a file
165 set backup " keep a backup after owerwriting a file
166 set backupdir=$XDG_CACHE_HOME/vim//
168 set undofile " persistent undo history
169 set undodir=$XDG_CACHE_HOME/vim//
171 set autowrite " automatically write a file when leaving a modified buffer
172 set autoread " automatically read a file that has been modified
176 set directory=$XDG_CACHE_HOME/vim//
178 " command line editing {{{2
179 set history=5000 " how many command lines are remembered
180 set wildmenu " command-line completion shows a list of matches
181 set wildmode=longest:full,full " specifies how command line completion works
183 set wildignore+=.hg,.git,.svn " Version control
184 set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
185 set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
186 set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
187 set wildignore+=*.spl " compiled spelling word lists
188 set wildignore+=*.sw? " Vim swap files
189 set wildignore+=*.luac " Lua byte code
190 set wildignore+=*.pyc " Python byte code
191 set wildignore+=*.orig " Merge resolution files
194 set virtualedit=block " let cursor move past last char in <C-V> mode
195 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
197 set viewdir=$XDG_CACHE_HOME/vim
200 " Resize splits when the window is resized {{{2
203 autocmd VimResized * :wincmd =
206 " Only show cursorline in the current window and in normal mode {{{2
209 au WinLeave,InsertEnter * set nocursorline
210 au WinEnter,InsertLeave * set cursorline
213 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
216 au StdinReadPost * :set buftype=nofile
219 " Jump to last known cursor position {{{2
222 " blacklist certain filetype
223 let blacklist = ['gitcommit']
224 autocmd BufReadPost *
225 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
226 \ exe "normal! g`\"" |
230 " auto source vimrc when saved {{{2
233 autocmd bufwritepost vimrc source $MYVIMRC
238 " allow both <space> and / to be <leader>
242 nnoremap <leader><cr> :make<cr>
245 nnoremap <silent> <Leader>/ :silent nohl<CR>
248 nnoremap <leader>[ :tabprev<cr>
249 nnoremap <leader>] :tabnext<cr>
252 nnoremap <leader>W :set wrap!<cr>
254 " paste from selection
255 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
256 " paste from clipboard
257 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
259 " Clean trailing whitespace
260 nnoremap <silent> <leader>ww m':%s/\s\+$//<cr>:let @/=''<cr>``zz
263 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
264 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
266 " jump to last cursor position
269 " Select (charwise) the contents of the current line, excluding indentation.
272 " Toggle [i]nvisible characters
273 nnoremap <leader>i :set list!<cr>
276 nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
279 nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
280 nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
287 " display the number of matches for the last search
288 nmap <Leader># :%s:<C-R>/::gn<CR>
290 " center cursor after search and open folds
294 " same when jumping around
297 nnoremap <c-o> <c-o>zzzv
299 " Not using the default mappings of 'To line from top/bottom'
305 " Heresy, emacs insert bindings
306 inoremap <c-a> <esc>I
307 inoremap <c-e> <esc>A
308 cnoremap <c-a> <home>
315 noremap <Right> <NOP>
317 inoremap <Down> <NOP>
318 inoremap <Left> <NOP>
319 inoremap <Right> <NOP>
321 cnoremap <Down> <NOP>
322 cnoremap <Left> <NOP>
323 cnoremap <Right> <NOP>
325 cnoremap <C-J> <Down>
326 cnoremap <C-H> <Left>
327 cnoremap <C-L> <Right>
329 " close all folds open fold in cursor
330 nnoremap zx zMzxzz15<C-e>
332 " edit vimrc in new tab
333 nmap <leader>ev :tabedit $MYVIMRC<CR>:lcd %:p:h<CR>
335 map <F1> :ls<CR>:b<space>
337 nnoremap <C-L> <C-W>w
338 nnoremap <C-H> <C-W>W
340 "xterm mouse with middleclick paste
341 nnoremap <MiddleMouse> i<MiddleMouse>
342 vnoremap <MiddleMouse> s<MiddleMouse>
344 " fix legacy vi inconsistency
347 " allow repeat operator on visual
348 vnoremap . :normal .<CR>
350 " add line without changing position or leaving mode
351 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
352 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
354 " Don't use Ex mode, use Q for formatting
357 " allow undoing in insert-mode
358 inoremap <C-U> <C-G>u<C-U>
359 inoremap <C-W> <C-G>u<C-W>
361 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
362 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
363 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
364 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
366 " space will toggle current fold in normal mode
367 nnoremap <leader><Space> za
368 " create folds around visual selection
369 vnoremap <leader><Space> zf
371 autocmd BufWinLeave *.* mkview
372 autocmd BufWinEnter *.* silent loadview
375 cnoremap w!! w !sudo tee % > /dev/null
379 let g:AgSmartCase = 1
380 nnoremap <leader>ag yiw:Ag
\12"<cr>
381 vnoremap <leader>ag y:Ag
\12"<cr>
384 let g:airline_detect_whitespace=2
385 let g:airline#extensions#tabline#enabled = 1
386 let g:airline_powerline_fonts = 1
389 nnoremap <F7> :GundoToggle<CR>
392 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
393 " delete fugitive buffers when closed
394 autocmd BufReadPost fugitive://* set bufhidden=delete
396 nnoremap <silent> <leader>gs :Gstatus<CR>
397 nnoremap <silent> <leader>gd :Gdiff<CR>
398 nnoremap <silent> <leader>gc :tab Gcommit -v<CR>
399 nnoremap <silent> <leader>gw :Gwrite<cr>
402 " open/close NERDTree with \e
403 nmap <Leader>e :NERDTreeToggle<CR>
404 nmap <F6> :NERDTreeToggle<CR>
405 " <space> to open files/dirs
406 let NERDTreeMapActivateNode='l'
407 " close vim if only NERDTree is open
408 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
411 let g:syntastic_enable_highlighting = 0
412 let g:syntastic_error_symbol='E'
413 let g:syntastic_style_error_symbol='S'
414 let g:syntastic_warning_symbol='W'
415 let g:syntastic_style_warning_symbol='S'
416 let g:syntastic_always_populate_loc_list=1
417 nmap <silent> <leader>y :SyntasticCheck<cr>
420 let g:syntastic_check_on_open=1
424 map <F5> :TagbarToggle<cr>
425 let g:tagbar_sort = 0
426 let g:tagbar_compact = 1
427 let g:tagbar_autoshowtag = 1
428 let g:tagbar_width = 25
429 let g:tagbar_iconchars = ['+', '-']
432 let g:UltiSnipsEditSplit = 'vertical'
433 let g:UltiSnipsSnippetsDir = "$XDG_CONFIG_HOME/vim/ultisnips"
436 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
437 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
438 let g:ycm_add_preview_to_completeopt = 1
439 let g:ycm_autoclose_preview_window_after_insertion = 1
440 "let g:ycm_extra_conf_vim_data = ['%:p']
441 nnoremap <leader>jd :YcmCompleter GoTo<CR>
444 let g:vim_json_syntax_conceal = 0
447 let g:tex_flavor='latex'
448 let g:Tex_DefaultTargetFormat='pdf'
449 let g:Tex_MultipleCompileFormats='pdf'
454 " Convenient command to see the difference between the current buffer and the
455 " file it was loaded from, thus the changes you made.
456 " Only define it when not defined already.
457 if !exists(":DiffOrig")
458 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
459 \ | wincmd p | diffthis
463 " http://tex.stackexchange.com/a/52932
464 let g:myLangList=["en_gb","en_us","de","fr"]
466 function! ToggleSpell()
467 if !exists("b:myLang")
470 execute "setlocal spell!"
472 echo "setlocal spelllang=" g:myLangList[b:myLang]
476 function! SwitchSpell()
477 if !exists("b:myLang")
481 let b:myLang=b:myLang+1
482 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
484 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
485 echo "setlocal spelllang=" g:myLangList[b:myLang]
488 nnoremap <silent> <Leader>s :call ToggleSpell()<CR>
489 nnoremap <silent> <Leader>S :call SwitchSpell()<CR>
490 " fix spelling with first choice
491 nnoremap <Leader>f 1z=
493 " Toggle line numbers {{{2
494 function! g:ToggleNumber()
495 if !exists("b:relanum")
499 let b:relanum = &relativenumber
500 setlocal nonumber norelativenumber
502 let &l:relativenumber = b:relanum
506 nnoremap <silent><leader>n :call g:ToggleNumber()<cr>
507 nnoremap <silent><leader>N :setlocal relativenumber!<cr>