Source

dotvim / vimrc

Full commit
" ===================================================
" .vimrc by Audrius Kažukauskas <audrius@neutrino.lt>
" for Vim version 7 or later
" ===================================================

set nocompatible

let mapleader = ','
let maplocalleader = ','

if v:version >= 703
  set colorcolumn=81
  set cryptmethod=blowfish
endif

" Set colorscheme, unless we're in console.
if &term != 'linux'
  if !has('gui_running')
    set t_Co=256
  endif
  colorscheme inkpot
endif

set autoindent
filetype plugin indent on
syntax on

" Whitespace.
set tabstop=8
set softtabstop=4
set shiftwidth=4
set expandtab
set smarttab

" Search and replace.
set incsearch
set ignorecase
set smartcase
set hlsearch
set gdefault

" Buffers.
set hidden
set switchbuf=useopen

" Editing.
set virtualedit=all
set pastetoggle=<F11>
set backspace=indent,eol,start
set nowrap
if v:version > 703 || (v:version == 703 && has('patch541'))
  set formatoptions+=j
endif

" Disable mouse support inside terminal emulator.
set mouse=

"Movement.
set scrolloff=3
set nostartofline

set history=100
set undolevels=100
set noerrorbells
set diffopt+=vertical
set sessionoptions-=help
set cpoptions+=J

" File contents.
set modelines=5
set fencs=ucs-bom,utf-8,latin7,latin1
set autoread

" Folding.
set foldmethod=marker

" Set title for terminal emulator.
set title
let &titleold = $USER . '@' . hostname() . ': ' .
      \ substitute(getcwd(), $HOME, '~', '')

set list listchars=tab-,trail:·,extends:>,precedes:<
" Rapidly toggle `set list'.
nmap <silent> <leader>l :set list!<CR>

" Ignore compiled Python files.
set suffixes+=.pyc,.pyo

" Don't search in included files when completing, too slow.
set complete-=i
set path=,,.,**3
set cdpath=,,.,$HOME
" Look for tags in parent dirs.
set tags+=./tags;$HOME

set nobackup
set backupcopy=auto,breakhardlink

" No swapfiles laying around.
set dir=~/tmp/vim

if !isdirectory(&dir)
  " Create the swapfile directory if it doesn't already exist.
  exec 'silent !mkdir -p ' . &dir
endif

" Spelling checker.
set spelllang=lt,en
set spellfile=~/.vim/spell/words.utf-8.add
" Toggle spell checking on and off with `,s`.
nmap <silent> <leader>s :set spell!<CR>

" When spliting windows, create new windows below and to the right.
set splitbelow splitright

" Status line.
" If pythonhelper.vim plugin can't be loaded, define dummy function.
if !exists('*TagInStatusLine')
  function TagInStatusLine()
    return ''
  endfunction
endif

function! HasLocalDir()
  if haslocaldir()
    return '[lcd]'
  endif
  return ''
endfunction

function! FileFormat()
  if &ff != 'unix'
    return '[' . &ff . ']'
  endif
  return ''
endfunction

set laststatus=2
set statusline=%3*%n:%*%<%f%m%r%h%w
set statusline+=\ %3*%{FileFormat()}%*%y
set statusline+=%2*%{HasLocalDir()}%*
set statusline+=%1*%{TagInStatusLine()}%*
set statusline+=%=\ %04l,%04v/%04L%4P
" Show (partial) command in the last line of the screen.
set showcmd
set wildmenu
set wildmode=longest,full
set wildignore+=*.pyc,*.pyo

" Persistent undo (Vim 7.3+).
if has('persistent_undo')
  " Enable persistent undo.
  set undofile
  " But don't clutter $PWD.
  let &undodir = &dir
endif

" Helper macro for ReST header markup.
let @h = 'YpVr'

" Python syntax.
let python_highlight_builtins = 0
let python_highlight_all = 1
let python_slow_sync = 1

" Bash syntax.
let readline_has_bash = 1
let g:is_bash = 1

" Hide Python byte code files in file browser.
let g:netrw_list_hide = '^\.[^.],.*\.py[co]$'

" Set width to 79 for all ReST files.
au FileType rst setlocal textwidth=79

au FileType xhtml,html,xml,xslt setlocal softtabstop=2 shiftwidth=2
au FileType rst,mail setlocal softtabstop=2 shiftwidth=2
au FileType make setlocal softtabstop=8 shiftwidth=8 noexpandtab

" Unload tarfile and zipfile buffers on :q to avoid errors while trying to
" reopen them (due to 'hidden' set).
" tarfile buffers are named using :file (triggers BufFilePost event).
au BufFilePost tarfile::*/* setlocal bufhidden=unload
" zipfile buffers are named using :e (triggers BufNew event).
au BufNew zipfile:*/* setlocal bufhidden=unload

" Don't screw up folds when inserting text that might affect them, until
" leaving insert mode.  'fdm' is local to the window.  Protect against
" screwing up folding when switching between windows.
au InsertEnter * if !exists('w:last_fdm') | let w:last_fdm=&fdm | setlocal fdm=manual | endif
au InsertLeave,WinLeave * if exists('w:last_fdm') | let &l:fdm=w:last_fdm | unlet w:last_fdm | endif

" man page configuration.
runtime ftplugin/man.vim
" $MANPAGER points to vim, reset it here for :Man command to work.
let $MANPAGER = ''

" Tagbar settings.
let g:tagbar_width = 35
let g:tagbar_compact = 1
let g:tagbar_autofocus = 1
let g:tagbar_autoclose = 1
nnoremap <silent> <F8> :TagbarToggle<CR>

function! Preserve(command)
  " Preparation: save last search, and cursor position.
  let _s = @/
  let l = line(".")
  let c = col(".")
  " Do the business:
  execute a:command
  " Clean up: restore previous search history, and cursor position.
  let @/ = _s
  call cursor(l, c)
endfunction

" Nuke trailing whitespace.
nmap            <leader>$       :call Preserve("%s/\\s\\+$//")<CR>
vmap            <leader>$       :s/\s\+$//<CR>

" Digraphs.
digraph `` 8220         " Left double quotation mark.
digraph '' 8221         " Right double quotation mark.
digraph ,, 8222         " Double low-9 quotation mark.

" Turn off search result highlighting.
nmap            <silent> <Esc>u :silent noh<CR>
nmap            <silent> <M-u>  :silent noh<CR>

" Use very magic mode by default when searching.
nnoremap        /               /\v
vnoremap        /               /\v
nnoremap        ?               ?\v
vnoremap        ?               ?\v

" Remember columns when jumping to marks.
map             '               `

" Undo in insert mode.
" Make it so that if I accidentally press ^W or ^U in insert mode,
" then <ESC>u will undo just the ^W/^U, and not the whole insert.
inoremap        <C-W>           <C-G>u<C-W>
inoremap        <C-U>           <C-G>u<C-U>

" .vimrc editing.
nmap            <leader>e       :e $MYVIMRC<CR>
nmap            <leader>v       :source $MYVIMRC<CR>
" Source .vimrc file after editing it.
au! BufWritePost .vimrc source $MYVIMRC

" Emacs style command line.
cnoremap        <C-G>           <C-C>
cnoremap        <C-A>           <Home>
cnoremap        <Esc>b          <S-Left>
cnoremap        <M-b>           <S-Left>
cnoremap        <Esc>f          <S-Right>
cnoremap        <M-f>           <S-Right>

" Move lines.
nnoremap        <C-j>           :m+<CR>==
nnoremap        <C-k>           :m-2<CR>==
vnoremap        <C-j>           :m'>+<CR>gv=gv
vnoremap        <C-k>           :m-2<CR>gv=gv

" Show the Unicode name of the character under cursor.
nmap            <F12>           :UnicodeName<CR>

" Use %% to represent directory of the file in the current buffer.
cabbrev         <expr> %%       expand('%:~:h')

" Open URI in browser.
func! OpenURI()
  let uri = getline('.')
  let uri = matchstr(uri, '\(http\|ftp\|file\)[^ \t>"' . nr2char(39) . ']\+')
  if uri == ''
    echo 'No URI found in line.'
  else
    let uri = escape(uri, '#&;|%')
    exec 'silent !opera "' . uri . '" &> /dev/null'
    if !has('gui_running')
      redraw!
    endif
  endif
endfunc
map <silent> <leader>u :call OpenURI()<CR>

" Tabular.vim mappings.
nmap <leader>a= :Tabularize /=<CR>
vmap <leader>a= :Tabularize /=<CR>
nmap <leader>a: :Tabularize /:\zs<CR>
vmap <leader>a: :Tabularize /:\zs<CR>

" sideways.vim mappings.
nnoremap <C-h> :SidewaysLeft<CR>
nnoremap <C-l> :SidewaysRight<CR>

" Gundo settings.
if v:version >= 703
  let g:gundo_width = 50
  let g:gundo_preview_height = 20
  let g:gundo_close_on_revert = 1
  nnoremap <F9> :GundoToggle<CR>
else
  let g:gundo_disable = 1
endif

" session.vim settings.
let g:session_autosave = 'yes'

" easytags.vim settings.
let g:easytags_file = '~/.vim/easytags'
let g:easytags_dynamic_files = 1
let g:easytags_auto_update = 0
let g:easytags_auto_highlight = 0
let g:easytags_updatetime_autodisable = 1

" Simple JavaScript Indenter settings.
let g:SimpleJsIndenter_BriefMode = 1
let g:SimpleJsIndenter_CaseIndentLevel = -1

" Set default SQL syntax to Postgres.
let g:sql_type_default = 'pgsql'


" {{{ GUI settings.
if has('gui_running')
  set number
  set numberwidth=6

  " Toolbars aren't needed.
  set guioptions-=T
  set guioptions-=m

  " Ditto to scrollbars.
  set guioptions-=r
  set guioptions-=L

  " Don't use GUI tabs.
  set guioptions-=e

  set guifont=DejaVu\ Sans\ Mono\ 9

  set lines=999
  set columns=9999

  set showtabline=2
  set mouse=a

  set switchbuf=usetab,newtab

  " Enable easytags.vim autoupdating only in GUI.
  let g:easytags_auto_update = 1

  " Disable cursor blinking.
  set gcr=a:blinkon0

  " Easy switching between buffers.
  nmap <silent> <A-k>  :wincmd k<CR>
  nmap <silent> <A-j>  :wincmd j<CR>
  nmap <silent> <A-h>  :wincmd h<CR>
  nmap <silent> <A-l>  :wincmd l<CR>
  imap <silent> <A-k>  <C-o>:wincmd k<CR>
  imap <silent> <A-j>  <C-o>:wincmd j<CR>
  imap <silent> <A-h>  <C-o>:wincmd h<CR>
  imap <silent> <A-l>  <C-o>:wincmd l<CR>

  " Tab navigation.
  nmap <silent> <A-Right>  :tabnext<CR>
  nmap <silent> <A-Left>   :tabprevious<CR>
  nmap <A-1>  1gt
  nmap <A-2>  2gt
  nmap <A-3>  3gt
  nmap <A-4>  4gt
  nmap <A-5>  5gt
  nmap <A-6>  6gt
  nmap <A-7>  7gt
  nmap <A-8>  8gt
  nmap <A-9>  9gt
  nmap <A-0>  :tablast<CR>
endif