3 " Maintainer:   Samir Benmendil <samir.benmendil[at]gmail[dot]com>
 
   6 if v:progname =~? "evim"
 
  10 " Use Vim settings, rather than Vi settings (much better!).
 
  11 " This must be first, because it changes other options as a side effect.
 
  14 " pathogen.vim runtime path manipulation
 
  15 silent! call pathogen#infect()
 
  22 nmap <Leader>q :nohl<CR>
 
  25 " open/close NERDTree with \e
 
  26 nmap <Leader>e :NERDTreeToggle<CR>
 
  27 " <space> to open files/dirs
 
  28 let NERDTreeMapActivateNode='<space>'
 
  29 " open NERDTree if no files were selected
 
  30 autocmd vimenter * if !argc() | NERDTree | endif
 
  31 " close vim if only NERDTree is open
 
  32 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
 
  35 let g:airline#extensions#tabline#enabled = 1
 
  38 :nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
 
  39 :nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
 
  40 :nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
 
  41 :nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
 
  45   set nobackup          " do not keep a backup file, use versions instead
 
  47   set backup            " keep a backup file
 
  48   set backupdir=$HOME/.vim/backupdir
 
  52 set background=dark            " Dark background, d'uh!
 
  53 set number                     " show some linenumbers
 
  54 set showmatch                  " Show matching brackets.
 
  55 set showbreak=▒▒                  " show these chars for wrapped lines
 
  56 set list listchars=tab:»·,trail:· " show these chars for tabs and trailing spaces
 
  59 set history=500                " keep 500 lines of command line history
 
  60 set ruler                      " show the cursor position all the time
 
  61 set confirm                    " Ask what to do when closing unsaved documents
 
  62 set showcmd                    " Show (partial) command in status line.
 
  63 set autowrite                  " Automatically save before commands like :next and :make
 
  64 "set hidden                    " Hide buffers when they are abandoned
 
  65 set splitright                 " split right when using :vsp
 
  66 set scrolloff=5                " keep at least n lines above/below
 
  67 set backspace=indent,eol,start " allow backspacing over everything in insert mode
 
  69 set viminfo='100,<50,s10,h,n~/.vim/viminfo " viminfo defaults but save file in .vim
 
  77 " Don't use Ex mode, use Q for formatting
 
  80 " CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
 
  81 " so that you can undo CTRL-U after inserting a line break.
 
  82 inoremap <C-U> <C-G>u<C-U>
 
  84 " Press `` to toggle insert and replace mode (no <Insert> key on Mac keyboard)
 
  88 nmap <F11> :set paste! paste?<CR>
 
  89 imap <F11> <C-o>:set paste!<CR>
 
  90 vmap <F11> <Esc>:set paste!<CR>gv
 
  94 " In many terminal emulators the mouse works just fine, thus enable it.
 
  96   "xterm mouse with middleclick paste
 
  97   nnoremap <MiddleMouse> i<MiddleMouse>
 
  98   vnoremap <MiddleMouse> s<MiddleMouse>
 
 106 " Switch syntax highlighting on, when the terminal has colors
 
 107 " Also switch on highlighting the last used search pattern.
 
 108 if &t_Co > 2 || has("gui_running")
 
 113 " Only do this part when compiled with support for autocommands.
 
 115   " Enable file type detection.
 
 116   " Use the default filetype settings, so that mail gets 'tw' set to 72,
 
 117   " 'cindent' is on in C files, etc.
 
 118   " Also load indent files, to automatically do language-dependent indenting.
 
 119   filetype plugin indent on
 
 121   " Put these in an autocmd group, so that we can delete them easily.
 
 125   " For all text files set 'textwidth' to 78 characters.
 
 126   autocmd FileType text setlocal textwidth=78
 
 128   " When editing a file, always jump to the last known cursor position.
 
 129   " Don't do it when the position is invalid or when inside an event handler
 
 130   " (happens when dropping a file on gvim).
 
 131   " Also don't do it when the mark is in the first line, that is the default
 
 132   " position when opening a file.
 
 133   " blacklist certain filetype, you can get a file type with :echo &ft
 
 134   let blacklist = ['gitcommit']
 
 135   autocmd BufReadPost *
 
 136     \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
 
 137     \   exe "normal! g`\"" |
 
 142   set autoindent                " always set autoindenting on
 
 143 endif " has("autocmd")
 
 146 " Convenient command to see the difference between the current buffer and the
 
 147 " file it was loaded from, thus the changes you made.
 
 148 " Only define it when not defined already.
 
 149 if !exists(":DiffOrig")
 
 150   command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
 
 151                   \ | wincmd p | diffthis
 
 155 set foldmethod=marker
 
 156 set foldlevelstart=99
 
 157 " space will toggle current fold in normal mode, if not in a fold, normal
 
 159 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
 
 161 " save and restore folds
 
 162 autocmd BufWinLeave *.* mkview
 
 163 autocmd BufWinEnter *.* silent loadview
 
 165 function! NextIndent(exclusive, fwd, lowerlevel, skipblanks) " {{{1
 
 166 " Jump to the next or previous line that has the same level or a lower
 
 167 " level of indentation than the current line.
 
 169 " exclusive (bool): true: Motion is exclusive
 
 170 " false: Motion is inclusive
 
 171 " fwd (bool): true: Go to next line
 
 172 " false: Go to previous line
 
 173 " lowerlevel (bool): true: Go to line with lower indentation level
 
 174 " false: Go to line with the same indentation level
 
 175 " skipblanks (bool): true: Skip blank lines
 
 176 " false: Don't skip blank lines
 
 178   let column = col('.')
 
 179   let lastline = line('$')
 
 180   let indent = indent(line)
 
 181   let stepvalue = a:fwd ? 1 : -1
 
 182   while (line > 0 && line <= lastline)
 
 183     let line = line + stepvalue
 
 184     if ( ! a:lowerlevel && indent(line) == indent ||
 
 185           \ a:lowerlevel && indent(line) < indent)
 
 186       if (! a:skipblanks || strlen(getline(line)) > 0)
 
 188           let line = line - stepvalue
 
 191         exe "normal " column . "|"
 
 198 " Moving back and forth between lines of same or lower indentation.
 
 199 nnoremap <silent> [l :call NextIndent(0, 0, 0, 1)<CR>
 
 200 nnoremap <silent> ]l :call NextIndent(0, 1, 0, 1)<CR>
 
 201 nnoremap <silent> [L :call NextIndent(0, 0, 1, 1)<CR>
 
 202 nnoremap <silent> ]L :call NextIndent(0, 1, 1, 1)<CR>
 
 203 vnoremap <silent> [l <Esc>:call NextIndent(0, 0, 0, 1)<CR>m'gv''
 
 204 vnoremap <silent> ]l <Esc>:call NextIndent(0, 1, 0, 1)<CR>m'gv''
 
 205 vnoremap <silent> [L <Esc>:call NextIndent(0, 0, 1, 1)<CR>m'gv''
 
 206 vnoremap <silent> ]L <Esc>:call NextIndent(0, 1, 1, 1)<CR>m'gv''
 
 207 onoremap <silent> [l :call NextIndent(0, 0, 0, 1)<CR>
 
 208 onoremap <silent> ]l :call NextIndent(0, 1, 0, 1)<CR>
 
 209 onoremap <silent> [L :call NextIndent(1, 0, 1, 1)<CR>
 
 210 onoremap <silent> ]L :call NextIndent(1, 1, 1, 1)<CR>