1. David Wolever
  2. dotfiles


dotfiles / vimrc

" Tab options
set tabstop=4       " When reading a file, show a tab ('\t') as 4 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
" 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
" Turn off highlighting when \ is pressed
map \ :noh

" 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)
autocmd BufEnter * map <C-A> :!%:p

" XML, HTML and Javascript have very bad indent settings... Don't use them.
autocmd BufEnter *.xml,*.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 showcmd         " Show (partial) command in status line.
set wildmenu        " Pretty command-line option 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]\ [HEX=\%02.2B]%=Y=%04l,\ X=%04v\ %p%%\ of\ %L\ (buf\ %n)
set laststatus=2 " Always show status line

" Folding opttions
set foldmethod=marker

" Python-specific things
" Use <C-A> to run .python files and fold them too!
autocmd BufEnter *.py map <C-A> :!python %
autocmd BufEnter *.py set foldmethod=indent
" Use F7, F8 and F9 to insert useful Python statements
map <F9> Oimport rpdb2; rpdb2.start_embedded_debugger("asdf") #BREAK
map <F8> Ofrom nose.tools import set_trace; set_trace() #BREAK
map <F7> Oimport traceback, sys; traceback.print_exception(*sys.exc_info()) #TRACEBACK

" 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> ok

" 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

" 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>

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

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

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