1. David Wolever
  2. dotfiles


dotfiles / vimrc

" Tab options
set tabstop=8       " When reading a file, show a tab ('\t') as 8 spaces
set softtabstop=4   " When inserting a tab (eg, pressing 'tab'), insert 4 spaces
set shiftwidth=4    " Number of spaces to indent when using '>>'
set expandtab       " Never insert an actual tab character -- always use spaces
set autoindent      " Copy indent from current line to next when enter is pressed
set history=1000    " Keep lots and lots of history
" See also: :help retab

" Formatting options
set formatoptions=cqn
" c: auto-wrap comments to textwidth
" q: Allow formatting comments with 'gq'
" n: Recognized numbered lists (eg: '1. ...\n 2. ... \n')
" See also: :help fo-table

" Searching options
set ignorecase   " Ignore case when searching
set smartcase    " See :help smartcase (trust me, it's useful)
set incsearch    " Incremental search
set hlsearch     " Hilight searches
" I use 'DW: ' to prefix lines during code review - this wraps them properly
" with 'gq'.
set comments-=b:#
set comments+=b:#\ DW\:,b:#

" Make sure that the leader is '\'
let mapleader="\\"

" Turn off highlighting when \ is pressed
map <leader>\ :noh<return>
" FuzzyFinder FTW http://www.vim.org/scripts/script.php?script_id=1984
map <leader>f :FufFile<CR>
map <leader>t :FufTag<CR>
map <leader>T :FufBufferTag<CR>
map <leader>b :FufBuffer<CR>
map <leader>j :FufJumpList<CR>
map <leader>c :FufChangeList<CR>

" File type things
syntax enable       " Turn on syntax hilighting
filetype on         " Enable filetype detection
filetype indent on  " Enable filetype-specific indenting
filetype plugin on  " Enable filetype-specific plugins

" Use <C-A> to execute the current file (equivilent to ./$FILE)
map <C-A> :!%:p<return>

" XML, HTML and Javascript have very bad indent settings... Don't use them.
" autocmd BufEnter *.js setlocal indentexpr= " Stop auto-indenting
" autocmd BufEnter *.js setlocal nocin
" autocmd BufEnter *.js setlocal smartindent
" autocmd BufEnter *.js setlocal autoindent

" When switching to a file, enter its directory
autocmd BufEnter * :lcd %:p:h

" Miscalanious stuff...
set backspace=indent,eol,start " Better backspacing
set ruler           " Show a ruler along the bottom of the screen
set lz              " Don't re-draw while running macros
set hid             " Can hide buffers without closing them
set shortmess=atI   " shortens messages to avoid 'press a key' prompt 
set scrolloff=3     " Always keep three lines above or below the cursor
set nocompatible    " Keep vim from trying to be 100% vi compatible
set title           " Set the window title
set showcmd         " Show (partial) command in status line.
set wildmenu        " Pretty command-line option matching
set wildmode=list:longest " Shell-style matching
set wildignore=*.bak,*.o,*.e,*~,*.pyc
" Suffixes that get lower priority when doing tab completion for filenames.
" These are files we are not likely to want to edit or read.
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc,.class,.pyc
set tags=tags;/
set statusline=%f%m%r%h%w\ [%Y]\ [0x\%02.2B]%<\ %F%=%4v,%4l\ %3p%%\ of\ %L
set laststatus=2    " Always show status line
set modelines=5     " Allow modelines within 5 lines of top/bottom

" Folding opttions
set foldmethod=marker

" When editing CPython source, run their provided vimrc (setting certain useful
" things like their coding standards)
let py_source = '\(Py3k-svn\|Python-trunk\)'
let path = expand('%:p:h')
if path =~ py_source
    let path = substitute(path, '\(.*/' . py_source . '\).*', '\1', '')
    execute('source ' . path . '/Misc/Vim/vimrc')

" Make p in Visual mode replace the selected text with the "" register.
vnoremap p <Esc>:let current_reg = @"<CR>gvdi<C-R>=current_reg<CR><Esc>

" Move to the first non-whitespace character when 0 is pressed and the first
" character on the line when ^ is pressed (instead of vice-versa)
noremap 0 ^
noremap ^ 0

" Use j and k to move down and up _logical_ lines instead of line-break lines
nmap j gj
nmap k gk

" Use <C-O> to insert a blank line below the current line
map <C-O> o<esc>k

" NetRW (the file browser) stuff... Safe to ignore :)
let g:netrw_sort_sequence='[\/]$,*,\.bak$,\.o$,\.h$,\.info$,\.swp$,\.obj$,\.pyc$'
let g:netrw_keepdir=0
let g:netrw_browse_split=0

" NERD tree
" Toggle
map <leader>d :execute 'NERDTreeToggle ' . getcwd()<CR>
" I often hit 'e' instead of 'o', so change the 'open explorer' from 'e' to
" 'E' (it's annoying to have an explorer open when I don't want one)
let g:NERDTreeMapOpenExpl = 'E'

" Some windowing convinience methods
map <c-h> <c-w>h
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-@> <c-w>_
map <c-space> <c-w>_
map + <c-w>+
map - <c-w>-

" Who needs arrow keys anyway?
map <right> :bn<return>
map <left> :bp<return>
map <up> :cp<return>
map <down> :cn<return>

"set t_kb=         " Fix backspace problems on some machines
"fixdel              " But this creates backspace problems on others... :(

" CSC369 stuff
let curpath = expand('%:p:h')
if curpath =~ 'CSC369/'
    " map gc (Goto Callers) to find all the places where <cword> is used
    map gc :grep -R <cword> ~/School/CSC369/src/kern/<return>
    " Setup the path so find will work
    set path=~/School/CSC369/src/**

" Exchange the jumping characteristics of ' and `
nnoremap ' `
nnoremap ` '

" Faster scrolling
nnoremap <C-e> <C-e><C-e><C-e>
nnoremap <C-y> <C-y><C-y><C-y>

" Uncomment this line to use <C-N> to open a terminal
" map  :!gnome-terminal &<Enter><Enter>

colorscheme tolerable
hi Folded ctermbg=none ctermfg=White cterm=none   
hi Pmenu ctermbg=none ctermfg=White cterm=none
hi PmenuSel ctermbg=darkgrey ctermfg=White cterm=none
hi PmenuThumb ctermbg=white ctermfg=white
hi PmenuSbar ctermbg=black ctermfg=black

" Match braces just by white-bolding them, not making them cyan
hi MatchParen ctermbg=none ctermfg=white term=bold cterm=bold
set showmatch    " Show matching brackets.
set matchtime=1

if has('gui_running')
    set guioptions-=T       " no toolbar

if has('cmdlog')
    set cmdlogdir=~/.vimlogs/

" Helpful for when other people use my Vim
fun! NoCrazyBindings()
    unmap <left>
    unmap <right>
    unmap <up>
    unmap <down>

" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
  \ if line("'\"") > 1 && line("'\"") <= line("$") |
  \   exe "normal! g`\"" |
  \ endif

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
		  \ | wincmd p | diffthis

" Make 'grep' ignore '.svn' directories and recurse
set grepprg=grep\ -R\ --exclude='*.svn*'\ -n\ $*

" Fix a diff, making it easier to review.
" Add a blank line before each '@@ ... hunk line info ...@@' and each 'diff',
" making it easier to jump around using { and }
fun! ReviewDiff()
    let oldreg_val = getreg('d')
    let oldreg_type = getregtype('d')
    call setreg('d', '', 'V')
    g/^diff/put! d
    g/^@@/put! d
    call setreg('d', oldreg_val, oldreg_type)

if has("mouse")
    set mouse=a

" Give me the option to confirm overwrites and other thigns without having to
" use '!'.
set confirm

" Words I can't spell
syn match Error /conneciton/
syn match Error /verticies/

" Enable perdy 256 color mode
" set t_Co=256