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 'wincent/Command-T'
 
  16 Bundle 'bling/vim-airline'
 
  20 Bundle 'The-NERD-tree'
 
  25 Bundle 'Valloric/YouCompleteMe'
 
  26 Bundle 'elzr/vim-json'
 
  28 filetype plugin indent on
 
  30 " moving around, searching and patterns {{{1
 
  31 set incsearch           " show match for partly typed search command
 
  32 set ignorecase          " ignore case when using a search pattern
 
  33 set smartcase           " override 'ignorecase' when pattern has upper case characters
 
  34 set hlsearch                    " highlight all matches for the last used search pattern
 
  36 " use leader-n to unhighlight search
 
  37 nmap <silent> <Leader>n :silent nohl<CR>
 
  38 " use leader-# to display the number of matches for the last search
 
  39 nmap <Leader># :%s:<C-R>/::gn<CR>
 
  40 " center cursor after search
 
  46 inoremap <Right> <NOP>
 
  52 set nostartofline       " don't  move the cursor to the first non-blank char of a line
 
  53 set path=.,**           " current + subdirectory search for :find, :grep:, ...
 
  55 " displaying text {{{1
 
  56 set scrolloff=5                 " number of screen lines to show around the cursor
 
  57 set wrap                        " long lines wrap
 
  58 set linebreak                   " wrap long lines at a character in 'breakat'
 
  59 set showbreak=▒▒                " show these chars for wrapped lines
 
  61 set lazyredraw                  " don't redraw while executing macros
 
  63 set list                        " show chars defined in 'listchars'
 
  64 set listchars=tab:»·,trail:·    " list of strings used for list mode
 
  66 set number                      " show the line number for each line
 
  67 set relativenumber              " show the relative line number for each line
 
  68 " toggle relativenumber
 
  69 nnoremap <silent> <Leader>u :exe "set relativenumber!"<CR>
 
  72   " When editing a file, always jump to the last known cursor position.
 
  73   " Don't do it when the position is invalid or when inside an event handler
 
  74   " (happens when dropping a file on gvim).
 
  75   " Also don't do it when the mark is in the first line, that is the default
 
  76   " position when opening a file.
 
  77   " blacklist certain filetype, you can get a file type with :echo &ft
 
  78   let blacklist = ['gitcommit']
 
  80     \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
 
  81     \   exe "normal! g`\"" |
 
  86 " syntax, highlighting and spelling {{{1
 
  87 set background=dark             " Dark background, d'uh!
 
  90 set spelllang=en_gb             " list of accepted languages
 
  91 set dictionary=spell            " list of dictionary files for keyword completion
 
  92 " toggle spell-checking
 
  93 map <silent><F10> :set nospell!<CR>:set nospell?<CR>
 
  97         \ if &omnifunc == "" | setl omnifunc=syntaxcomplete#Complete | endif
 
 100 " multiple windows {{{1
 
 101 set laststatus=2                " 0, 1 or 2; when to use a status line for the last window
 
 103 set previewheight=20            " default height for the preview window
 
 105 set splitright                  " a new window is put right of the current one
 
 112 map <F1> :ls<CR>:b<space>
 
 114 " using the mouse {{{1
 
 115 set mouse=rnv                   " list of flags for using the mouse
 
 116 set ttymouse=xterm              " type of mouse
 
 118 "xterm mouse with middleclick paste
 
 119 nnoremap <MiddleMouse> i<MiddleMouse>
 
 120 vnoremap <MiddleMouse> s<MiddleMouse>
 
 122 " messages and info {{{1
 
 123 set showcmd                     " Show (partial) command in status line.
 
 124 set ruler                       " show the cursor position all the time
 
 125 set confirm                     " Ask what to do when closing unsaved documents
 
 128 set backspace=indent,eol,start  " allow backspacing over everything in insert mode
 
 130 set showmatch                   " Show matching brackets.
 
 132 set nojoinspaces                " don't use two spaces after '.' when joining a line
 
 133 set formatoptions+=j            " remove comment leader when joining lines
 
 135 set nrformats=hex               " number formats recognized for CTRL-A and CTRL-X commands
 
 137 " whether to use a popup menu for Insert mode completion
 
 138 set completeopt=longest,menuone,preview
 
 140 " Indent if we're at the beginning of a line. Else, do completion.
 
 141 function! InsertTabWrapper()
 
 142   let col = col('.') - 1
 
 143   if !col || getline('.')[col - 1] !~ '\k'
 
 149 inoremap <Tab> <C-R>=InsertTabWrapper()<CR>
 
 150 inoremap <S-Tab> <C-P>
 
 152 " fix legacy vi inconsistency
 
 155 " allow repeat operator on visual
 
 156 vnoremap . :normal .<CR>
 
 158 " add line without changing position or leaving mode
 
 159 map <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
 
 160 map <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
 
 162 " Don't use Ex mode, use Q for formatting
 
 165 " allow undoing in insert-mode
 
 166 inoremap <C-U> <C-G>u<C-U>
 
 167 inoremap <C-W> <C-G>u<C-W>
 
 169 " tabs and indent {{{1
 
 170 set shiftwidth=4                " number of spaces used for each step of (auto)indent
 
 171 set smarttab                    " a <Tab> in an indent inserts 'shiftwidth' spaces
 
 172 set softtabstop=4               " if non-zero, number of spaces to insert for a <Tab>
 
 173 set shiftround                  " round to 'shiftwidth' for "<<" and ">>"
 
 174 set expandtab                   " expand <Tab> to spaces in Insert mode
 
 176 set cindent                     " use smart C indenting (see :h C-indenting)
 
 177 set cinoptions=l1,c4,(0,U1,w1,m1,j1,J1
 
 179 set pastetoggle=<F11>           " key sequence to toggle paste mode
 
 181 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
 
 182 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
 
 183 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
 
 184 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
 
 187 set foldmethod=marker           " folding type
 
 188 set foldlevelstart=0            " value for 'foldlevel' when starting to edit a file
 
 190 " space will toggle current fold in normal mode
 
 191 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
 
 192 " create folds around visual selection
 
 195 " save and restore folds
 
 196 autocmd BufWinLeave *.* mkview
 
 197 autocmd BufWinEnter *.* silent loadview
 
 199 " reading and writing files {{{1
 
 200 set writebackup                 " write a backup file before overwriting a file
 
 201 set backup                      " keep a backup after owerwriting a file
 
 202 set backupdir=$XDG_CACHE_HOME/vim
 
 204 set undofile                    " persistent undo history
 
 205 set undodir=$XDG_CACHE_HOME/vim
 
 207 set autowrite                   " automatically write a file when leaving a modified buffer
 
 210 cmap w!! w !sudo tee % > /dev/null
 
 213 set directory=$XDG_CACHE_HOME/vim,.,/var/tmp
 
 215 " command line editing {{{1
 
 216 set history=500                 " how many command lines are remembered
 
 217 set wildmode=longest:full       " specifies how command line completion works
 
 218 set wildmenu                    " command-line completion shows a list of matches
 
 221 set virtualedit=block           " let cursor move past last char in <C-V> mode
 
 222 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .vim
 
 224 set viewdir=$XDG_CACHE_HOME/vim
 
 228 let g:airline_detect_whitespace=2
 
 229 let g:airline_whitespace_symbol = 'Ξ'
 
 230 let g:airline_linecolumn_prefix = '␊ '
 
 231 let g:airline_left_sep = '▶'
 
 232 let g:airline_right_sep = '◀'
 
 233 let g:airline#extensions#tabline#enabled = 1
 
 236 nnoremap <F7> :GundoToggle<CR>
 
 238 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
 
 241 " open/close NERDTree with \e
 
 242 nmap <Leader>e :NERDTreeToggle<CR>
 
 243 nmap <F6> :NERDTreeToggle<CR>
 
 244 " <space> to open files/dirs
 
 245 let NERDTreeMapActivateNode='<space>'
 
 246 " open NERDTree if no files were selected
 
 247 autocmd vimenter * if !argc() | NERDTree | endif
 
 248 " close vim if only NERDTree is open
 
 249 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
 
 252 let g:syntastic_enable_highlighting = 0
 
 253 let g:syntastic_error_symbol='E'
 
 254 let g:syntastic_style_error_symbol='S'
 
 255 let g:syntastic_warning_symbol='W'
 
 256 let g:syntastic_style_warning_symbol='S'
 
 257 let g:syntastic_always_populate_loc_list=1
 
 258 nmap <silent> <leader>y :SyntasticCheck<cr>
 
 261    let g:syntastic_check_on_open=1
 
 265 map <F5> :TagbarToggle<cr>
 
 266 let g:tagbar_sort = 0
 
 267 let g:tagbar_compact = 1
 
 268 let g:tagbar_autoshowtag = 1
 
 269 let g:tagbar_width = 25
 
 270 let g:tagbar_iconchars = ['+', '-']
 
 273 let g:ycm_extra_conf_globlist = ['/mnt/data/src/*']
 
 276 let g:vim_json_syntax_conceal = 0
 
 279 " Convenient command to see the difference between the current buffer and the
 
 280 " file it was loaded from, thus the changes you made.
 
 281 " Only define it when not defined already.
 
 282 if !exists(":DiffOrig")
 
 283   command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
 
 284                   \ | wincmd p | diffthis