3 " Author:   Samir Benmendil <samir.benmendil[at]gmail[dot]com>
 
   6 filetype plugin indent on
 
   8 " pathogen.vim runtime path manipulation
 
   9 silent! call pathogen#infect()
 
  11 " moving around, searching and patterns {{{1
 
  12 set incsearch           " show match for partly typed search command
 
  13 set ignorecase          " ignore case when using a search pattern
 
  14 set smartcase           " override 'ignorecase' when pattern has upper case characters
 
  15 set hlsearch                    " highlight all matches for the last used search pattern
 
  17 " use leader-n to unhighlight search
 
  18 nmap <silent> <Leader>n :silent nohl<CR>
 
  19 " use leader-# to display the number of matches for the last search
 
  20 nmap <Leader># :%s:<C-R>/::gn<CR>
 
  22 set nostartofline       " don't  move the cursor to the first non-blank char of a line
 
  23 set path=.,**           " current + subdirectory search for :find, :grep:, ...
 
  25 " displaying text {{{1
 
  26 set scrolloff=5                 " number of screen lines to show around the cursor
 
  27 set wrap                        " long lines wrap
 
  28 set linebreak                   " wrap long lines at a character in 'breakat'
 
  29 set showbreak=▒▒                " show these chars for wrapped lines
 
  31 set lazyredraw                  " don't redraw while executing macros
 
  33 set list                        " show chars defined in 'listchars'
 
  34 set listchars=tab:»·,trail:·    " list of strings used for list mode
 
  36 set number                      " show the line number for each line
 
  37 set relativenumber              " show the relative line number for each line
 
  38 " toggle relativenumber
 
  39 nnoremap <silent> <Leader>u :exe "set relativenumber!"<CR>
 
  42   " When editing a file, always jump to the last known cursor position.
 
  43   " Don't do it when the position is invalid or when inside an event handler
 
  44   " (happens when dropping a file on gvim).
 
  45   " Also don't do it when the mark is in the first line, that is the default
 
  46   " position when opening a file.
 
  47   " blacklist certain filetype, you can get a file type with :echo &ft
 
  48   let blacklist = ['gitcommit']
 
  50     \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
 
  51     \   exe "normal! g`\"" |
 
  56 " syntax, highlighting and spelling {{{1
 
  57 set background=dark             " Dark background, d'uh!
 
  60 set spelllang=en,de,fr          " list of accepted languages
 
  61 set dictionary=spell            " list of dictionary files for keyword completion
 
  62 " toggle spell-checking
 
  63 map <silent><F10> :set nospell!<CR>:set nospell?<CR>
 
  67         \ if &omnifunc == "" | setl omnifunc=syntaxcomplete#Complete | endif
 
  70 " multiple windows {{{1
 
  71 set laststatus=2                " 0, 1 or 2; when to use a status line for the last window
 
  73 set previewheight=20            " default height for the preview window
 
  75 set splitright                  " a new window is put right of the current one
 
  82 map <F1> :ls<CR>:b<space>
 
  84 " using the mouse {{{1
 
  85 set mouse=rnv                   " list of flags for using the mouse
 
  86 set ttymouse=xterm              " type of mouse
 
  88 "xterm mouse with middleclick paste
 
  89 nnoremap <MiddleMouse> i<MiddleMouse>
 
  90 vnoremap <MiddleMouse> s<MiddleMouse>
 
  92 " messages and info {{{1
 
  93 set showcmd                     " Show (partial) command in status line.
 
  94 set ruler                       " show the cursor position all the time
 
  95 set confirm                     " Ask what to do when closing unsaved documents
 
  98 set backspace=indent,eol,start  " allow backspacing over everything in insert mode
 
 100 set showmatch                   " Show matching brackets.
 
 102 set nojoinspaces                " don't use two spaces after '.' when joining a line
 
 103 set formatoptions+=j            " remove comment leader when joining lines
 
 105 set nrformats=hex               " number formats recognized for CTRL-A and CTRL-X commands
 
 107 " whether to use a popup menu for Insert mode completion
 
 108 set completeopt=longest,menuone,preview
 
 110 " Indent if we're at the beginning of a line. Else, do completion.
 
 111 function! InsertTabWrapper()
 
 112   let col = col('.') - 1
 
 113   if !col || getline('.')[col - 1] !~ '\k'
 
 119 inoremap <Tab> <C-R>=InsertTabWrapper()<CR>
 
 120 inoremap <S-Tab> <C-P>
 
 122 " fix legacy vi inconsistency
 
 125 " allow repeat operator on visual
 
 126 vnoremap . :normal .<CR>
 
 128 " add line without changing position or leaving mode
 
 129 map <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
 
 130 map <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
 
 132 " Don't use Ex mode, use Q for formatting
 
 135 " allow undoing in insert-mode
 
 136 inoremap <C-U> <C-G>u<C-U>
 
 137 inoremap <C-W> <C-G>u<C-W>
 
 139 " tabs and indent {{{1
 
 140 set shiftwidth=4                " number of spaces used for each step of (auto)indent
 
 141 set smarttab                    " a <Tab> in an indent inserts 'shiftwidth' spaces
 
 142 set softtabstop=4               " if non-zero, number of spaces to insert for a <Tab>
 
 143 set shiftround                  " round to 'shiftwidth' for "<<" and ">>"
 
 144 set expandtab                   " expand <Tab> to spaces in Insert mode
 
 146 set cindent                     " use smart C indenting (see :h C-indenting)
 
 147 set cinoptions=l1,c4,(0,U1,w1,m1,j1,J1
 
 149 set pastetoggle=<F11>           " key sequence to toggle paste mode
 
 151 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
 
 152 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
 
 153 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
 
 154 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
 
 157 set foldmethod=marker           " folding type
 
 158 set foldlevelstart=99           " value for 'foldlevel' when starting to edit a file
 
 160 " space will toggle current fold in normal mode
 
 161 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
 
 162 " create folds around visual selection
 
 165 " save and restore folds
 
 166 autocmd BufWinLeave *.* mkview
 
 167 autocmd BufWinEnter *.* silent loadview
 
 169 " reading and writing files {{{1
 
 170 set writebackup                 " write a backup file before overwriting a file
 
 171 set backup                      " keep a backup after owerwriting a file
 
 172 set backupdir=$HOME/.vim/backupdir
 
 174 set undofile                    " persistent undo history
 
 175 set undodir=$HOME/.vim/backupdir
 
 177 set autowrite                   " automatically write a file when leaving a modified buffer
 
 179 " command line editing {{{1
 
 180 set history=500                 " how many command lines are remembered
 
 181 set wildmode=longest:full       " specifies how command line completion works
 
 182 set wildmenu                    " command-line completion shows a list of matches
 
 185 set virtualedit=block           " let cursor move past last char in <C-V> mode
 
 186 set viminfo='100,<50,s10,h,n~/.vim/viminfo " viminfo defaults but save file in .vim
 
 190 let g:airline_detect_whitespace=2
 
 191 let g:airline_whitespace_symbol = 'Ξ'
 
 192 let g:airline_linecolumn_prefix = '␊ '
 
 193 let g:airline_left_sep = '▶'
 
 194 let g:airline_right_sep = '◀'
 
 195 let g:airline#extensions#tabline#enabled = 1
 
 198 nnoremap <F7> :GundoToggle<CR>
 
 200 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
 
 203 " open/close NERDTree with \e
 
 204 nmap <Leader>e :NERDTreeToggle<CR>
 
 205 nmap <F6> :NERDTreeToggle<CR>
 
 206 " <space> to open files/dirs
 
 207 let NERDTreeMapActivateNode='<space>'
 
 208 " open NERDTree if no files were selected
 
 209 autocmd vimenter * if !argc() | NERDTree | endif
 
 210 " close vim if only NERDTree is open
 
 211 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
 
 214 let g:syntastic_enable_highlighting = 0
 
 215 let g:syntastic_error_symbol='E'
 
 216 let g:syntastic_style_error_symbol='S'
 
 217 let g:syntastic_warning_symbol='W'
 
 218 let g:syntastic_style_warning_symbol='S'
 
 219 let g:syntastic_always_populate_loc_list=1
 
 220 nmap <silent> <leader>y :SyntasticCheck<cr>
 
 223    let g:syntastic_check_on_open=1
 
 227 map <F5> :TagbarToggle<cr>
 
 228 let g:tagbar_sort = 0
 
 229 let g:tagbar_compact = 1
 
 230 let g:tagbar_autoshowtag = 1
 
 231 let g:tagbar_width = 25
 
 232 let g:tagbar_iconchars = ['+', '-']
 
 235 " Convenient command to see the difference between the current buffer and the
 
 236 " file it was loaded from, thus the changes you made.
 
 237 " Only define it when not defined already.
 
 238 if !exists(":DiffOrig")
 
 239   command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
 
 240                   \ | wincmd p | diffthis