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
 
 172 set writebackup                 " write a backup file before overwriting a file
 
 173 set backup                      " keep a backup after owerwriting a file
 
 174 set backupdir=$XDG_CACHE_HOME/vim//
 
 176 set undofile                    " persistent undo history
 
 177 set undodir=$XDG_CACHE_HOME/vim//
 
 179 set autowrite                   " automatically write a file when leaving a modified buffer
 
 180 set autoread                    " automatically read a file that has been modified
 
 184 set directory=$XDG_CACHE_HOME/vim//
 
 186 " command line editing {{{2
 
 187 set history=5000                " how many command lines are remembered
 
 188 set wildmenu                    " command-line completion shows a list of matches
 
 189 set wildmode=longest:full,full  " specifies how command line completion works
 
 191 set wildignore+=.hg,.git,.svn                    " Version control
 
 192 set wildignore+=*.aux,*.out,*.toc                " LaTeX intermediate files
 
 193 set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg   " binary images
 
 194 set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
 
 195 set wildignore+=*.spl                            " compiled spelling word lists
 
 196 set wildignore+=*.sw?                            " Vim swap files
 
 197 set wildignore+=*.luac                           " Lua byte code
 
 198 set wildignore+=*.pyc                            " Python byte code
 
 199 set wildignore+=*.orig                           " Merge resolution files
 
 202 set virtualedit=block           " let cursor move past last char in <C-V> mode
 
 203 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
 
 205 set viewdir=$XDG_CACHE_HOME/vim
 
 208 " Resize splits when the window is resized {{{2
 
 211     autocmd VimResized * :wincmd =
 
 214 " Only show cursorline in the current window and in normal mode {{{2
 
 217     au WinLeave,InsertEnter * set nocursorline
 
 218     au WinEnter,InsertLeave * set cursorline
 
 221 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
 
 224     au StdinReadPost * :set buftype=nofile
 
 227 " Jump to last known cursor position {{{2
 
 230     " blacklist certain filetype
 
 231     let blacklist = ['gitcommit']
 
 232     autocmd BufReadPost *
 
 233                 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
 
 234                 \   exe "normal! g`\"" |
 
 240 " allow both <space> and / to be <leader>
 
 244 nnoremap <leader><cr> :make<cr>
 
 247 nnoremap <silent> <Leader>/ :silent nohl<CR>
 
 250 nnoremap <leader>[ :tabprev<cr>
 
 251 nnoremap <leader>] :tabnext<cr>
 
 254 nnoremap <leader>W :set wrap!<cr>
 
 256 " paste from selection
 
 257 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
 
 258 " paste from clipboard
 
 259 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
 
 261 " Clean trailing whitespace
 
 262 nnoremap <silent> <leader>ww m':%s/\s\+$//<cr>:let @/=''<cr>``zz
 
 265 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
 
 266 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
 
 268 " jump to last cursor position
 
 271 " Select (charwise) the contents of the current line, excluding indentation.
 
 274 " Toggle [i]nvisible characters
 
 275 nnoremap <leader>i :set list!<cr>
 
 278 nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
 
 281 nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
 
 282 nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
 
 289 " display the number of matches for the last search
 
 290 nmap <Leader># :%s:<C-R>/::gn<CR>
 
 292 " center cursor after search and open folds
 
 296 " same when jumping around
 
 299 nnoremap <c-o> <c-o>zzzv
 
 301 " Not using the default mappings of 'To line from top/bottom'
 
 307 " Heresy, emacs insert bindings
 
 308 inoremap <c-a> <esc>I
 
 309 inoremap <c-e> <esc>A
 
 310 cnoremap <c-a> <home>
 
 313 " proper movement when lines are wrapped
 
 314 noremap <expr> j (v:count == 0 ? 'gj' : 'j')
 
 315 noremap <expr> k (v:count == 0 ? 'gk' : 'k')
 
 321 noremap  <Right> <NOP>
 
 323 inoremap <Down>  <NOP>
 
 324 inoremap <Left>  <NOP>
 
 325 inoremap <Right> <NOP>
 
 327 cnoremap <Down>  <NOP>
 
 328 cnoremap <Left>  <NOP>
 
 329 cnoremap <Right> <NOP>
 
 331 cnoremap <C-J>   <Down>
 
 332 cnoremap <C-H>   <Left>
 
 333 cnoremap <C-L>   <Right>
 
 335 " close all folds open fold in cursor
 
 338 " edit vimrc in new tab
 
 339 nmap <leader>ev :tabedit $MYVIMRC<CR>:lcd %:p:h<CR>
 
 341 map <F1> :ls<CR>:b<space>
 
 343 nnoremap <C-L> <C-W>w
 
 344 nnoremap <C-H> <C-W>W
 
 346 "xterm mouse with middleclick paste
 
 347 nnoremap <MiddleMouse> i<MiddleMouse>
 
 348 vnoremap <MiddleMouse> s<MiddleMouse>
 
 350 " fix legacy vi inconsistency
 
 353 " allow repeat operator on visual
 
 354 vnoremap . :normal .<CR>
 
 356 " add line without changing position or leaving mode
 
 357 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
 
 358 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
 
 360 " Don't use Ex mode, use Q for formatting
 
 363 " allow undoing in insert-mode
 
 364 inoremap <C-U> <C-G>u<C-U>
 
 365 inoremap <C-W> <C-G>u<C-W>
 
 367 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
 
 368 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
 
 369 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
 
 370 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
 
 372 " space will toggle current fold in normal mode
 
 373 nnoremap <leader><Space> za
 
 374 " create folds around visual selection
 
 375 vnoremap <leader><Space> zf
 
 377 autocmd BufWinLeave *.* mkview
 
 378 autocmd BufWinEnter *.* silent loadview
 
 381 cnoremap w!! w !sudo tee % > /dev/null
 
 385 let g:AgSmartCase = 1
 
 386 nnoremap <leader>ag yiw:Ag 
\12"<cr>
 
 387 vnoremap <leader>ag y:Ag 
\12"<cr>
 
 390 let g:airline_detect_whitespace=2
 
 391 let g:airline#extensions#tabline#enabled = 1
 
 392 let g:airline_powerline_fonts = 1
 
 395 let g:checkattach_filebrowser = 'ranger'
 
 398 let delimitMate_expand_cr = 2
 
 399 let g:delimitMate_expand_space = 1
 
 402 nnoremap <silent> <Leader>ff :FSHere<CR>
 
 403 nnoremap <silent> <Leader>fl :FSRight<CR>
 
 404 nnoremap <silent> <Leader>fh :FSLeft<CR>
 
 405 nnoremap <silent> <Leader>fL :FSSplitRight<CR>
 
 406 nnoremap <silent> <Leader>fH :FSSplitLeft<CR>
 
 409 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
 
 410 " delete fugitive buffers when closed
 
 411 autocmd BufReadPost fugitive://* set bufhidden=delete
 
 413 nnoremap <silent> <leader>gs :Gstatus<CR>
 
 414 nnoremap <silent> <leader>gd :Gdiff<CR>
 
 415 nnoremap <silent> <leader>gc :tab Gcommit -v<CR>
 
 416 nnoremap <silent> <leader>ga :Gwrite<cr>
 
 417 nnoremap <silent> <leader>gb :Gblame<cr>
 
 420 nnoremap <F7> :GundoToggle<CR>
 
 423 let g:indent_guides_default_mapping = 0
 
 424 let g:indent_guides_guide_size = 1
 
 425 nmap <silent> cog <Plug>IndentGuidesToggle
 
 426 nmap <silent> [og <Plug>IndentGuidesEnable
 
 427 nmap <silent> ]og <Plug>IndentGuidesDisable
 
 430 " open/close NERDTree with \e
 
 431 nmap <Leader>e :NERDTreeToggle<CR>
 
 432 nmap <F6> :NERDTreeToggle<CR>
 
 433 " <space> to open files/dirs
 
 434 let NERDTreeMapActivateNode='l'
 
 435 " close vim if only NERDTree is open
 
 436 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
 
 440 let g:pymode_rope_completion = 0
 
 441 let g:pymode_rope = 0
 
 442 let g:pymode_folding = 1
 
 443 let g:pymode_lint_ignore = "E221,E266,E501"
 
 444 let g:pymode_syntax_space_errors = 0    " don't bother me when I'm typing
 
 447 let g:syntastic_enable_highlighting = 0
 
 448 let g:syntastic_error_symbol='E'
 
 449 let g:syntastic_style_error_symbol='S'
 
 450 let g:syntastic_warning_symbol='W'
 
 451 let g:syntastic_style_warning_symbol='S'
 
 452 let g:syntastic_always_populate_loc_list=1
 
 453 nmap <silent> <leader>y :SyntasticCheck<cr>
 
 456   let g:syntastic_check_on_open=1
 
 460 map <F5> :TagbarToggle<cr>
 
 461 let g:tagbar_sort = 0
 
 462 let g:tagbar_compact = 1
 
 463 let g:tagbar_autoshowtag = 1
 
 464 let g:tagbar_width = 25
 
 465 let g:tagbar_iconchars = ['+', '-']
 
 468 let g:UltiSnipsEditSplit = 'vertical'
 
 469 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
 
 470 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
 
 471 let g:UltiSnipsExpandTrigger = "<C-L>"
 
 472 let g:UltiSnipsJumpForwardTrigger = "<C-L>"
 
 473 let g:UltiSnipsJumpBackwardTrigger = "<C-H>"
 
 476 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
 
 477 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
 
 478 let g:ycm_extra_conf_vim_data = ['getcwd()']
 
 479 let g:ycm_add_preview_to_completeopt = 1
 
 480 let g:ycm_autoclose_preview_window_after_insertion = 1
 
 481 "let g:ycm_extra_conf_vim_data = ['%:p']
 
 482 nnoremap <leader>jd :YcmCompleter GoTo<CR>
 
 484 " vim-easy-align {{{2
 
 485 " start interactive EasyAlign in visual mode
 
 486 vmap <Enter> <Plug>(EasyAlign)
 
 489 let g:vim_json_syntax_conceal = 0
 
 492 let g:tex_flavor='latex'
 
 493 let g:Tex_DefaultTargetFormat='pdf'
 
 494 let g:Tex_MultipleCompileFormats='pdf'
 
 499 " Convenient command to see the difference between the current buffer and the
 
 500 " file it was loaded from, thus the changes you made.
 
 501 " Only define it when not defined already.
 
 502 if !exists(":DiffOrig")
 
 503   command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
 
 504                   \ | wincmd p | diffthis
 
 508 " http://tex.stackexchange.com/a/52932
 
 509 let g:myLangList=["en_gb","en_us","de","fr"]
 
 511 function! ToggleSpell()
 
 512   if !exists("b:myLang")
 
 515   execute "setlocal spell!"
 
 517     echo "setlocal spelllang=" g:myLangList[b:myLang]
 
 521 function! SwitchSpell()
 
 522   if !exists("b:myLang")
 
 526     let b:myLang=b:myLang+1
 
 527     if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
 
 529   execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
 
 530   echo "setlocal spelllang=" g:myLangList[b:myLang]
 
 533 nnoremap <silent> <Leader>s :call ToggleSpell()<CR>
 
 534 nnoremap <silent> <Leader>S :call SwitchSpell()<CR>
 
 535 " fix spelling with first choice
 
 536 nnoremap <Leader>f 1z=