3 " Author:   Samir Benmendil <samir.benmendil[at]gmail[dot]com>
 
   7 set runtimepath=$XDG_CONFIG_HOME/vim,$VIMRUNTIME,$XDG_CONFIG_HOME/vim/after
 
  11 set rtp+=$XDG_DATA_HOME/vim/vundle
 
  12 call vundle#rc('$XDG_DATA_HOME/vim')
 
  14 Bundle 'gmarik/vundle'
 
  15 Bundle 'bling/vim-airline'
 
  19 Bundle 'The-NERD-tree'
 
  24 Bundle 'Valloric/YouCompleteMe'
 
  25 Bundle 'elzr/vim-json'
 
  26 Bundle 'http://git.code.sf.net/p/vim-latex/vim-latex'
 
  27 Bundle 'ervandew/ag.git'
 
  29 filetype plugin indent on
 
  31 " moving around, searching and patterns {{{1
 
  32 set incsearch           " show match for partly typed search command
 
  33 set ignorecase          " ignore case when using a search pattern
 
  34 set smartcase           " override 'ignorecase' when pattern has upper case characters
 
  35 set hlsearch                    " highlight all matches for the last used search pattern
 
  37 " use leader-n to unhighlight search
 
  38 nmap <silent> <Leader>n :silent nohl<CR>
 
  39 " use leader-# to display the number of matches for the last search
 
  40 nmap <Leader># :%s:<C-R>/::gn<CR>
 
  41 " center cursor after search
 
  47 inoremap <Right> <NOP>
 
  53 set nostartofline       " don't  move the cursor to the first non-blank char of a line
 
  54 set path=.,**           " current + subdirectory search for :find, :grep:, ...
 
  56 " displaying text {{{1
 
  57 set scrolloff=5                 " number of screen lines to show around the cursor
 
  58 set wrap                        " long lines wrap
 
  59 set linebreak                   " wrap long lines at a character in 'breakat'
 
  60 set showbreak=▒▒                " show these chars for wrapped lines
 
  62 set lazyredraw                  " don't redraw while executing macros
 
  64 set list                        " show chars defined in 'listchars'
 
  65 set listchars=tab:»·,trail:·    " list of strings used for list mode
 
  67 set number                      " show the line number for each line
 
  68 set relativenumber              " show the relative line number for each line
 
  69 " toggle relativenumber
 
  70 nnoremap <silent> <Leader>u :exe "set relativenumber!"<CR>
 
  73   " When editing a file, always jump to the last known cursor position.
 
  74   " Don't do it when the position is invalid or when inside an event handler
 
  75   " (happens when dropping a file on gvim).
 
  76   " Also don't do it when the mark is in the first line, that is the default
 
  77   " position when opening a file.
 
  78   " blacklist certain filetype, you can get a file type with :echo &ft
 
  79   let blacklist = ['gitcommit']
 
  81     \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
 
  82     \   exe "normal! g`\"" |
 
  87 " syntax, highlighting and spelling {{{1
 
  88 set background=dark             " Dark background, d'uh!
 
  91 set spelllang=en_gb             " list of accepted languages
 
  92 set dictionary=spell            " list of dictionary files for keyword completion
 
  93 " Spell Check http://tex.stackexchange.com/a/52932
 
  95 let g:myLangList=["nospell","en_gb","en_us","de","fr"]
 
  96 function! ToggleSpell()
 
  97   let b:myLang=b:myLang+1
 
  98   if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
 
 102     execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
 
 104   echo "spell checking language:" g:myLangList[b:myLang]
 
 106 map <F10> :call ToggleSpell()<CR>
 
 107 imap <F10> <C-O>:call ToggleSpell()<CR>
 
 111         \ if &omnifunc == "" | setl omnifunc=syntaxcomplete#Complete | endif
 
 114 " multiple windows {{{1
 
 115 set laststatus=2                " 0, 1 or 2; when to use a status line for the last window
 
 117 set previewheight=20            " default height for the preview window
 
 119 set splitright                  " a new window is put right of the current one
 
 126 map <F1> :ls<CR>:b<space>
 
 128 " using the mouse {{{1
 
 129 set mouse=rnv                   " list of flags for using the mouse
 
 130 set ttymouse=xterm              " type of mouse
 
 132 "xterm mouse with middleclick paste
 
 133 nnoremap <MiddleMouse> i<MiddleMouse>
 
 134 vnoremap <MiddleMouse> s<MiddleMouse>
 
 136 " messages and info {{{1
 
 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
 
 142 set backspace=indent,eol,start  " allow backspacing over everything in insert mode
 
 144 set showmatch                   " Show matching brackets.
 
 146 set nojoinspaces                " don't use two spaces after '.' when joining a line
 
 147 set formatoptions+=j            " remove comment leader when joining lines
 
 149 set nrformats=hex               " number formats recognized for CTRL-A and CTRL-X commands
 
 151 " whether to use a popup menu for Insert mode completion
 
 152 set completeopt=longest,menuone,preview
 
 154 " Indent if we're at the beginning of a line. Else, do completion.
 
 155 function! InsertTabWrapper()
 
 156   let col = col('.') - 1
 
 157   if !col || getline('.')[col - 1] !~ '\k'
 
 163 inoremap <Tab> <C-R>=InsertTabWrapper()<CR>
 
 164 inoremap <S-Tab> <C-P>
 
 166 " fix legacy vi inconsistency
 
 169 " allow repeat operator on visual
 
 170 vnoremap . :normal .<CR>
 
 172 " add line without changing position or leaving mode
 
 173 map <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
 
 174 map <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
 
 176 " Don't use Ex mode, use Q for formatting
 
 179 " allow undoing in insert-mode
 
 180 inoremap <C-U> <C-G>u<C-U>
 
 181 inoremap <C-W> <C-G>u<C-W>
 
 183 " tabs and indent {{{1
 
 184 set shiftwidth=4                " number of spaces used for each step of (auto)indent
 
 185 set smarttab                    " a <Tab> in an indent inserts 'shiftwidth' spaces
 
 186 set softtabstop=4               " if non-zero, number of spaces to insert for a <Tab>
 
 187 set shiftround                  " round to 'shiftwidth' for "<<" and ">>"
 
 188 set expandtab                   " expand <Tab> to spaces in Insert mode
 
 190 set cindent                     " use smart C indenting (see :h C-indenting)
 
 191 set cinoptions=l1,c4,(0,U1,w1,m1,j1,J1
 
 193 set pastetoggle=<F11>           " key sequence to toggle paste mode
 
 195 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
 
 196 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
 
 197 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
 
 198 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
 
 201 set foldmethod=marker           " folding type
 
 202 set foldlevelstart=0            " value for 'foldlevel' when starting to edit a file
 
 204 " space will toggle current fold in normal mode
 
 205 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
 
 206 " create folds around visual selection
 
 209 " save and restore folds
 
 210 set viewoptions=folds,cursor    " don't save local options
 
 211 autocmd BufWinLeave *.* mkview
 
 212 autocmd BufWinEnter *.* silent loadview
 
 214 " reading and writing files {{{1
 
 215 set writebackup                 " write a backup file before overwriting a file
 
 216 set backup                      " keep a backup after owerwriting a file
 
 217 set backupdir=$XDG_CACHE_HOME/vim
 
 219 set undofile                    " persistent undo history
 
 220 set undodir=$XDG_CACHE_HOME/vim
 
 222 set autowrite                   " automatically write a file when leaving a modified buffer
 
 225 cmap w!! w !sudo tee % > /dev/null
 
 228 set directory=$XDG_CACHE_HOME/vim,.,/var/tmp
 
 230 " command line editing {{{1
 
 231 set history=500                 " how many command lines are remembered
 
 232 set wildmode=longest:full       " specifies how command line completion works
 
 233 set wildmenu                    " command-line completion shows a list of matches
 
 236 set virtualedit=block           " let cursor move past last char in <C-V> mode
 
 237 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .vim
 
 239 set viewdir=$XDG_CACHE_HOME/vim
 
 243 let g:airline_detect_whitespace=2
 
 244 let g:airline_whitespace_symbol = 'Ξ'
 
 245 let g:airline_linecolumn_prefix = '␊ '
 
 246 let g:airline_left_sep = '▶'
 
 247 let g:airline_right_sep = '◀'
 
 248 let g:airline#extensions#tabline#enabled = 1
 
 251 nnoremap <F7> :GundoToggle<CR>
 
 253 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
 
 256 " open/close NERDTree with \e
 
 257 nmap <Leader>e :NERDTreeToggle<CR>
 
 258 nmap <F6> :NERDTreeToggle<CR>
 
 259 " <space> to open files/dirs
 
 260 let NERDTreeMapActivateNode='<space>'
 
 261 " close vim if only NERDTree is open
 
 262 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
 
 265 let g:syntastic_enable_highlighting = 0
 
 266 let g:syntastic_error_symbol='E'
 
 267 let g:syntastic_style_error_symbol='S'
 
 268 let g:syntastic_warning_symbol='W'
 
 269 let g:syntastic_style_warning_symbol='S'
 
 270 let g:syntastic_always_populate_loc_list=1
 
 271 nmap <silent> <leader>y :SyntasticCheck<cr>
 
 274    let g:syntastic_check_on_open=1
 
 278 map <F5> :TagbarToggle<cr>
 
 279 let g:tagbar_sort = 0
 
 280 let g:tagbar_compact = 1
 
 281 let g:tagbar_autoshowtag = 1
 
 282 let g:tagbar_width = 25
 
 283 let g:tagbar_iconchars = ['+', '-']
 
 286 let g:ycm_extra_conf_globlist = ['/mnt/data/src/*']
 
 289 let g:vim_json_syntax_conceal = 0
 
 292 let g:tex_flavor='latex'
 
 293 let g:Tex_DefaultTargetFormat='pdf'
 
 296 " Convenient command to see the difference between the current buffer and the
 
 297 " file it was loaded from, thus the changes you made.
 
 298 " Only define it when not defined already.
 
 299 if !exists(":DiffOrig")
 
 300   command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
 
 301                   \ | wincmd p | diffthis