1 " An example for a vimrc file.
 
   3 " Maintainer:   Bram Moolenaar <Bram@vim.org>
 
   4 " Last change:  2008 Dec 17
 
   6 " To use it, copy it to
 
   7 "     for Unix and OS/2:  ~/.vimrc
 
   9 "  for MS-DOS and Win32:  $VIM\_vimrc
 
  10 "           for OpenVMS:  sys$login:.vimrc
 
  12 " When started as "evim", evim.vim will already have done these settings.
 
  13 if v:progname =~? "evim"
 
  18 " organize this file, never thought it'll get this big
 
  21 " pathogen.vim runtime path manipulation
 
  22 silent! call pathogen#infect()
 
  24 " Use Vim settings, rather than Vi settings (much better!).
 
  25 " This must be first, because it changes other options as a side effect.
 
  28 " allow backspacing over everything in insert mode
 
  29 set backspace=indent,eol,start
 
  32   set nobackup          " do not keep a backup file, use versions instead
 
  34   set backup            " keep a backup file
 
  35   set backupdir=$HOME/.vim/backupdir
 
  37 set history=50          " keep 50 lines of command line history
 
  38 set ruler               " show the cursor position all the time
 
  39 set showcmd             " display incomplete commands
 
  40 set incsearch           " do incremental searching
 
  41 set number              " show some linenumbers
 
  43 " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
 
  44 " let &guioptions = substitute(&guioptions, "t", "", "g")
 
  46 " Don't use Ex mode, use Q for formatting
 
  49 " CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
 
  50 " so that you can undo CTRL-U after inserting a line break.
 
  51 inoremap <C-U> <C-G>u<C-U>
 
  54 nmap <F11> :set paste! paste?<CR>
 
  55 imap <F11> <C-o>:set paste!<CR>
 
  56 vmap <F11> <Esc>:set paste!<CR>gv
 
  59 " In many terminal emulators the mouse works just fine, thus enable it.
 
  61 "  "xterm mouse with middleclick paste
 
  62 "  nnoremap <MiddleMouse> i<MiddleMouse>
 
  63 "  vnoremap <MiddleMouse> s<MiddleMouse>
 
  67 "  "set ttymouse=xterm2
 
  70 " Switch syntax highlighting on, when the terminal has colors
 
  71 " Also switch on highlighting the last used search pattern.
 
  72 if &t_Co > 2 || has("gui_running")
 
  77 " Only do this part when compiled with support for autocommands.
 
  80   " Enable file type detection.
 
  81   " Use the default filetype settings, so that mail gets 'tw' set to 72,
 
  82   " 'cindent' is on in C files, etc.
 
  83   " Also load indent files, to automatically do language-dependent indenting.
 
  84   filetype plugin indent on
 
  86   " Put these in an autocmd group, so that we can delete them easily.
 
  90   " For all text files set 'textwidth' to 78 characters.
 
  91   autocmd FileType text setlocal textwidth=78
 
  93   " When editing a file, always jump to the last known cursor position.
 
  94   " Don't do it when the position is invalid or when inside an event handler
 
  95   " (happens when dropping a file on gvim).
 
  96   " Also don't do it when the mark is in the first line, that is the default
 
  97   " position when opening a file.
 
  98   " blacklist certain filetype, you can get a file type with :echo &ft
 
  99   let blacklist = ['gitcommit']
 
 100   autocmd BufReadPost *
 
 101     \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
 
 102     \   exe "normal! g`\"" |
 
 109   set autoindent                " always set autoindenting on
 
 111 endif " has("autocmd")
 
 113 " Convenient command to see the difference between the current buffer and the
 
 114 " file it was loaded from, thus the changes you made.
 
 115 " Only define it when not defined already.
 
 116 if !exists(":DiffOrig")
 
 117   command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
 
 118                   \ | wincmd p | diffthis
 
 121 " Ask what to do when closing unsaved documents
 
 124 " If using a dark background within the editing area and syntax highlighting
 
 125 " turn on this option as well
 
 128 " The following are commented out as they cause vim to behave a lot
 
 129 " differently from regular Vi. They are highly recommended though.
 
 130 set showcmd             " Show (partial) command in status line.
 
 131 set showmatch           " Show matching brackets.
 
 132 set ignorecase          " Do case insensitive matching
 
 133 set smartcase           " Do smart case matching
 
 134 set incsearch           " Incremental search
 
 135 set autowrite           " Automatically save before commands like :next and :make
 
 136 "set hidden             " Hide buffers when they are abandoned
 
 137 "set mouse=a            " Enable mouse usage (all modes)
 
 145 " show these chars for tabs and trailing spaces
 
 146 set list listchars=tab:»·,trail:·
 
 148 set pastetoggle=<F11>
 
 149 " split right when using :vsp
 
 152 set scrolloff=3             " keep at least 3 lines above/below
 
 153 " Press i to enter insert mode, and ii to exit.
 
 155 " Press `` to toggle insert and replace mode (no <Insert> key on Mac keyboard)
 
 158 " fold between {{{ }}}
 
 159 set foldmethod=marker
 
 160 set foldlevelstart=99
 
 161 " space will toggle current fold in normal mode, if not in a fold, normal
 
 163 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
 
 165 " save and restore folds
 
 166 autocmd BufWinLeave *.* mkview
 
 167 autocmd BufWinEnter *.* silent loadview
 
 169 " Jump to the next or previous line that has the same level or a lower
 
 170 " level of indentation than the current line.
 
 172 " exclusive (bool): true: Motion is exclusive
 
 173 " false: Motion is inclusive
 
 174 " fwd (bool): true: Go to next line
 
 175 " false: Go to previous line
 
 176 " lowerlevel (bool): true: Go to line with lower indentation level
 
 177 " false: Go to line with the same indentation level
 
 178 " skipblanks (bool): true: Skip blank lines
 
 179 " false: Don't skip blank lines
 
 180 function! NextIndent(exclusive, fwd, lowerlevel, skipblanks)
 
 182   let column = col('.')
 
 183   let lastline = line('$')
 
 184   let indent = indent(line)
 
 185   let stepvalue = a:fwd ? 1 : -1
 
 186   while (line > 0 && line <= lastline)
 
 187     let line = line + stepvalue
 
 188     if ( ! a:lowerlevel && indent(line) == indent ||
 
 189           \ a:lowerlevel && indent(line) < indent)
 
 190       if (! a:skipblanks || strlen(getline(line)) > 0)
 
 192           let line = line - stepvalue
 
 195         exe "normal " column . "|"
 
 202 " Moving back and forth between lines of same or lower indentation.
 
 203 nnoremap <silent> [l :call NextIndent(0, 0, 0, 1)<CR>
 
 204 nnoremap <silent> ]l :call NextIndent(0, 1, 0, 1)<CR>
 
 205 nnoremap <silent> [L :call NextIndent(0, 0, 1, 1)<CR>
 
 206 nnoremap <silent> ]L :call NextIndent(0, 1, 1, 1)<CR>
 
 207 vnoremap <silent> [l <Esc>:call NextIndent(0, 0, 0, 1)<CR>m'gv''
 
 208 vnoremap <silent> ]l <Esc>:call NextIndent(0, 1, 0, 1)<CR>m'gv''
 
 209 vnoremap <silent> [L <Esc>:call NextIndent(0, 0, 1, 1)<CR>m'gv''
 
 210 vnoremap <silent> ]L <Esc>:call NextIndent(0, 1, 1, 1)<CR>m'gv''
 
 211 onoremap <silent> [l :call NextIndent(0, 0, 0, 1)<CR>
 
 212 onoremap <silent> ]l :call NextIndent(0, 1, 0, 1)<CR>
 
 213 onoremap <silent> [L :call NextIndent(1, 0, 1, 1)<CR>
 
 214 onoremap <silent> ]L :call NextIndent(1, 1, 1, 1)<CR>