3 " Author:   Samir Benmendil <samir.benmendil[at]gmail[dot]com>
 
   8 set runtimepath& " reset rtp
 
  11 set runtimepath+=$XDG_DATA_HOME/vim/vundle
 
  12 call vundle#rc('$XDG_DATA_HOME/vim')
 
  14 Bundle 'gmarik/vundle'
 
  16 Bundle 'bling/vim-airline'
 
  17 Bundle 'elzr/vim-json'
 
  18 Bundle 'ervandew/ag.git'
 
  19 Bundle 'http://git.code.sf.net/p/vim-latex/vim-latex'
 
  20 Bundle 'kien/ctrlp.vim'
 
  21 Bundle 'kshenoy/vim-signature'
 
  22 Bundle 'majutsushi/tagbar'
 
  23 Bundle 'scrooloose/nerdtree'
 
  24 Bundle 'scrooloose/syntastic'
 
  25 Bundle 'sjl/gundo.vim'
 
  26 Bundle 'tomtom/tcomment_vim'
 
  27 Bundle 'tpope/vim-endwise'
 
  28 Bundle 'tpope/vim-fugitive'
 
  29 Bundle 'tpope/vim-repeat'
 
  30 Bundle 'tpope/vim-surround'
 
  31 Bundle 'tpope/vim-unimpaired'
 
  32 Bundle 'valloric/youcompleteme'
 
  34 Bundle 'ompugao/ros.vim'
 
  35 Bundle 'ompugao/ctrlp-ros'
 
  37 Bundle 'firef0x/pkgbuild.vim'
 
  38 Bundle 'derekwyatt/vim-fswitch'
 
  39 " seems to have problems right now... may be add later?
 
  40 "Bundle 'jalcine/cmake.vim' 
 
  41 Bundle 'powerman/vim-plugin-viewdoc'
 
  43 " remove entries first
 
  44 set runtimepath -=$HOME/.vim
 
  45 set runtimepath -=$HOME/.vim/after
 
  46 set runtimepath -=$XDG_CONFIG_HOME/vim
 
  47 set runtimepath -=$XDG_CONFIG_HOME/vim/after
 
  48 " then prepend and append them
 
  49 set runtimepath ^=$XDG_CONFIG_HOME/vim
 
  50 set runtimepath +=$XDG_CONFIG_HOME/vim/after
 
  52 filetype plugin indent on
 
  55 " allow both <space> and / to be <leader>
 
  57 nnoremap <leader><cr> :make<cr>
 
  59 " moving around, searching and patterns {{{1
 
  60 set incsearch           " show match for partly typed search command
 
  61 set ignorecase          " ignore case when using a search pattern
 
  62 set smartcase           " override 'ignorecase' when pattern has upper case characters
 
  63 set hlsearch            " highlight all matches for the last used search pattern
 
  65 " use leader-n to unhighlight search
 
  66 nmap <silent> <Leader>n :silent nohl<CR>
 
  67 " use leader-# to display the number of matches for the last search
 
  68 nmap <Leader># :%s:<C-R>/::gn<CR>
 
  69 " center cursor after search
 
  80 inoremap <Right> <NOP>
 
  84 cnoremap <Right> <NOP>
 
  88 cnoremap <C-L>   <Right>
 
  90 set nostartofline       " don't  move the cursor to the first non-blank char of a line
 
  91 set path=.,include/,../include/,/usr/include/c++/*,/opt/ros/hydro/include
 
  93 " displaying text {{{1
 
  94 set scrolloff=5                 " number of screen lines to show around the cursor
 
  95 set nowrap                      " long lines wrap
 
  96 set linebreak                   " wrap long lines at a character in 'breakat'
 
  97 set showbreak=▒▒                " show these chars for wrapped lines
 
  99 set lazyredraw                  " don't redraw while executing macros
 
 101 set list                        " show chars defined in 'listchars'
 
 102 set listchars=tab:»·,trail:·    " list of strings used for list mode
 
 103 set listchars+=extends:⋯,precedes:⋯
 
 104 set sidescrolloff=1             " don't scroll over the listchars
 
 106 set number                      " show the line number for each line
 
 107 set relativenumber              " show the relative line number for each line
 
 108 " toggle relativenumber
 
 109 nnoremap <silent> <Leader>u :exe "set relativenumber!"<CR>
 
 112   " When editing a file, always jump to the last known cursor position.
 
 113   " Don't do it when the position is invalid or when inside an event handler
 
 114   " (happens when dropping a file on gvim).
 
 115   " Also don't do it when the mark is in the first line, that is the default
 
 116   " position when opening a file.
 
 117   " blacklist certain filetype, you can get a file type with :echo &ft
 
 118   let blacklist = ['gitcommit']
 
 119   autocmd BufReadPost *
 
 120     \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
 
 121     \   exe "normal! g`\"" |
 
 126 " syntax, highlighting and spelling {{{1
 
 130 set dictionary=spell            " list of dictionary files for keyword completion
 
 131 " Spell Check http://tex.stackexchange.com/a/52932
 
 133 let g:myLangList=["en_gb","en_us","de","fr"]
 
 135 function! ToggleSpell()
 
 136   execute "setlocal spell!"
 
 138     echo "setlocal spelllang=" g:myLangList[b:myLang]
 
 141 nnoremap <silent> <Leader>s :call ToggleSpell()<CR>
 
 143 function! SwitchSpell()
 
 145     let b:myLang=b:myLang+1
 
 146     if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
 
 148   execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
 
 149   echo "setlocal spelllang=" g:myLangList[b:myLang]
 
 151 nnoremap <silent> <Leader>S :call SwitchSpell()<CR>
 
 153 " fix spelling with first choice
 
 154 nnoremap <Leader>f 1z=
 
 158         \ if &omnifunc == "" | setl omnifunc=syntaxcomplete#Complete | endif
 
 161 " multiple windows {{{1
 
 162 set laststatus=2                " 0, 1 or 2; when to use a status line for the last window
 
 164 set previewheight=20            " default height for the preview window
 
 166 set splitright                  " a new window is put right of the current one
 
 168 map <F1> :ls<CR>:b<space>
 
 173 " using the mouse {{{1
 
 174 set mouse=rnv                   " list of flags for using the mouse
 
 175 set ttymouse=xterm              " type of mouse
 
 177 "xterm mouse with middleclick paste
 
 178 nnoremap <MiddleMouse> i<MiddleMouse>
 
 179 vnoremap <MiddleMouse> s<MiddleMouse>
 
 181 " messages and info {{{1
 
 182 set showcmd                     " Show (partial) command in status line.
 
 183 set ruler                       " show the cursor position all the time
 
 184 set confirm                     " Ask what to do when closing unsaved documents
 
 185 set shortmess=filnxtoOI         " don't show intro message
 
 188 set backspace=indent,eol,start  " allow backspacing over everything in insert mode
 
 190 set showmatch                   " Show matching brackets.
 
 192 set nojoinspaces                " don't use two spaces after '.' when joining a line
 
 193 set formatoptions+=j            " remove comment leader when joining lines
 
 195 set nrformats=hex               " number formats recognized for CTRL-A and CTRL-X commands
 
 197 " whether to use a popup menu for Insert mode completion
 
 198 set completeopt=longest,menuone,preview
 
 200 " Indent if we're at the beginning of a line. Else, do completion.
 
 201 function! InsertTabWrapper()
 
 202   let col = col('.') - 1
 
 203   if !col || getline('.')[col - 1] !~ '\k'
 
 209 inoremap <Tab> <C-R>=InsertTabWrapper()<CR>
 
 210 inoremap <S-Tab> <C-P>
 
 212 " fix legacy vi inconsistency
 
 215 " allow repeat operator on visual
 
 216 vnoremap . :normal .<CR>
 
 218 " add line without changing position or leaving mode
 
 219 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
 
 220 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
 
 222 " Don't use Ex mode, use Q for formatting
 
 225 " allow undoing in insert-mode
 
 226 inoremap <C-U> <C-G>u<C-U>
 
 227 inoremap <C-W> <C-G>u<C-W>
 
 229 " tabs and indent {{{1
 
 230 set shiftwidth=4                " number of spaces used for each step of (auto)indent
 
 231 set smarttab                    " a <Tab> in an indent inserts 'shiftwidth' spaces
 
 232 set softtabstop=4               " if non-zero, number of spaces to insert for a <Tab>
 
 233 set shiftround                  " round to 'shiftwidth' for "<<" and ">>"
 
 234 set expandtab                   " expand <Tab> to spaces in Insert mode
 
 236 set cindent                     " use smart C indenting (see :h C-indenting)
 
 237 set cinoptions=l1,c4,(0,U1,w1,m1,j1,J1
 
 239 set pastetoggle=<F11>           " key sequence to toggle paste mode
 
 241 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
 
 242 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
 
 243 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
 
 244 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
 
 247 set foldmethod=marker           " folding type
 
 248 set foldlevelstart=0            " value for 'foldlevel' when starting to edit a file
 
 250 " space will toggle current fold in normal mode
 
 251 nnoremap <leader><Space> za
 
 252 " create folds around visual selection
 
 253 vnoremap <leader><Space> zf
 
 255 " save and restore folds
 
 256 set viewoptions=folds,cursor    " don't save local options
 
 257 autocmd BufWinLeave *.* mkview
 
 258 autocmd BufWinEnter *.* silent loadview
 
 260 " reading and writing files {{{1
 
 261 set writebackup                 " write a backup file before overwriting a file
 
 262 set backup                      " keep a backup after owerwriting a file
 
 263 set backupdir=$XDG_CACHE_HOME/vim
 
 265 set undofile                    " persistent undo history
 
 266 set undodir=$XDG_CACHE_HOME/vim
 
 268 set autowrite                   " automatically write a file when leaving a modified buffer
 
 271 cmap w!! w !sudo tee % > /dev/null
 
 274 set directory=$XDG_CACHE_HOME/vim,.,/var/tmp
 
 276 " command line editing {{{1
 
 277 set history=500                 " how many command lines are remembered
 
 278 set wildmode=longest:full,full  " specifies how command line completion works
 
 279 set wildmenu                    " command-line completion shows a list of matches
 
 282 set virtualedit=block           " let cursor move past last char in <C-V> mode
 
 283 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
 
 285 set viewdir=$XDG_CACHE_HOME/vim
 
 289 let g:airline_detect_whitespace=2
 
 290 let g:airline#extensions#tabline#enabled = 1
 
 291 let g:airline_powerline_fonts = 1
 
 294 "let g:goldenview__enable_default_mapping = 0
 
 295 "nmap <silent> <C-N>   <Plug>GoldenViewSplit
 
 296 "nmap <silent> <C-L>   <Plug>GoldenViewNext
 
 297 "nmap <silent> <C-H>   <Plug>GoldenViewPrevious
 
 298 "nmap <silent> <C-M>   <Plug>GoldenViewSwitchMain
 
 299 "nmap <silent> <C-S-M> <Plug>GoldenViewPrevious
 
 302 nnoremap <F7> :GundoToggle<CR>
 
 304 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
 
 305 " delete fugitive buffers when closed
 
 306 autocmd BufReadPost fugitive://* set bufhidden=delete
 
 308 nnoremap <silent> <leader>gs :Gstatus<CR>
 
 309 nnoremap <silent> <leader>gd :Gdiff<CR>
 
 310 nnoremap <silent> <leader>gc :tab Gcommit -v<CR>
 
 313 " open/close NERDTree with \e
 
 314 nmap <Leader>e :NERDTreeToggle<CR>
 
 315 nmap <F6> :NERDTreeToggle<CR>
 
 316 " <space> to open files/dirs
 
 317 let NERDTreeMapActivateNode='<space>'
 
 318 " close vim if only NERDTree is open
 
 319 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
 
 322 let g:syntastic_enable_highlighting = 0
 
 323 let g:syntastic_error_symbol='E'
 
 324 let g:syntastic_style_error_symbol='S'
 
 325 let g:syntastic_warning_symbol='W'
 
 326 let g:syntastic_style_warning_symbol='S'
 
 327 let g:syntastic_always_populate_loc_list=1
 
 328 nmap <silent> <leader>y :SyntasticCheck<cr>
 
 331   let g:syntastic_check_on_open=1
 
 335 map <F5> :TagbarToggle<cr>
 
 336 let g:tagbar_sort = 0
 
 337 let g:tagbar_compact = 1
 
 338 let g:tagbar_autoshowtag = 1
 
 339 let g:tagbar_width = 25
 
 340 let g:tagbar_iconchars = ['+', '-']
 
 343 let g:ycm_extra_conf_globlist = ['~/src/*']
 
 346 let g:vim_json_syntax_conceal = 0
 
 349 let g:tex_flavor='latex'
 
 350 let g:Tex_DefaultTargetFormat='pdf'
 
 353 let g:no_viewdoc_maps = 1
 
 354 nnoremap K :call ViewDoc('doc', '<cword>')<cr>
 
 357 " auto source vimrc when saved
 
 358 autocmd bufwritepost vimrc source $MYVIMRC
 
 359 nmap <leader>v :tabedit $MYVIMRC<CR>
 
 361 " Convenient command to see the difference between the current buffer and the
 
 362 " file it was loaded from, thus the changes you made.
 
 363 " Only define it when not defined already.
 
 364 if !exists(":DiffOrig")
 
 365   command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
 
 366                   \ | wincmd p | diffthis