Source

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

" Vundle
set runtimepath+=~/.vim/bundle/vundle/
call vundle#rc()

Bundle 'gmarik/vundle'

Bundle 'closetag.vim'
Bundle 'matchit.zip'
Bundle 'gnupg.vim'
Bundle 'pyflakes'
Bundle 'gsession.vim'
Bundle 'hail2u/vim-css3-syntax'


" TODO: look at this... It seems neat
"let g:ipy_perform_mappings = 0
"Bundle 'vim-ipython'
"map <silent> <F5> :python run_this_file()<CR>
"map <silent> <S-F5> :python run_this_line()<CR>
"map <silent> <F9> :python run_these_lines()<CR>
"map <silent> <leader>d :py get_doc_buffer()<CR>
"map <silent> <leader>s :py update_subchannel_msgs(); echo("vim-ipython shell updated",'Operator')<CR>
"map <silent> <S-F9> :python toggle_reselect()<CR>
""map <silent> <C-F6> :python send('%pdb')<CR>
""map <silent> <F6> :python set_breakpoint()<CR>
""map <silent> <s-F6> :python clear_breakpoint()<CR>
""map <silent> <F7> :python run_this_file_pdb()<CR>
""map <silent> <s-F7> :python clear_all_breaks()<CR>
"imap <C-F5> <C-O><F5>
"imap <S-F5> <C-O><S-F5>
"imap <silent> <F5> <C-O><F5>
"map <C-F5> :call <SID>toggle_send_on_save()<CR>
""" Example of how to quickly clear the current plot with a keystroke
""map <silent> <F12> :python run_command("plt.clf()")<cr>
""" Example of how to quickly close all figures with a keystroke
""map <silent> <F11> :python run_command("plt.close('all')")<cr>
"
""pi custom
"map <silent> <C-Return> :python run_this_file()<CR>
"map <silent> <C-s> :python run_this_line()<CR>
"imap <silent> <C-s> <C-O>:python run_this_line()<CR>
"map <silent> <M-s> :python dedent_run_this_line()<CR>
"vmap <silent> <C-S> :python run_these_lines()<CR>
"vmap <silent> <M-s> :python dedent_run_these_lines()<CR>
"map <silent> <M-c> I#<ESC>
"vmap <silent> <M-c> I#<ESC>
"map <silent> <M-C> :s/^\([ \t]*\)#/\1/<CR>
"vmap <silent> <M-C> :s/^\([ \t]*\)#/\1/<CR>

Bundle 'FuzzyFinder'
map <leader>f :FufFile<CR>
map <leader>t :FufTag<CR>
map <leader>b :FufBuffer<CR>
map <leader>g :FufTaggedFile<CR>
map <leader>T :FufTaggedFile<CR>

Bundle 'The-NERD-tree'
" 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'


" HardTabs([width=8]): Sets up the current buffers so that:
" - '\t' is 'widith' wide
" - '<tab>' inserts a '\t'
" - '>>' shifts one tab
fun! HardTabs(...)
    let width = (a:0 > 0? a:1 : 8)
    let &l:tabstop=width
    let &l:softtabstop=width
    let &l:shiftwidth=width
    let &l:expandtab=0
endfun

" SoftTabs([softWidth=4, [hardWidth=8]]): Sets up the current buffers so that:
" - '\t' is 'hardWidth' wide
" - '<tab>' inserts 'softWidth' spaces
" - '>>' shifts with 'softWidth' spaces
fun! SoftTabs(...)
    let softWidth = (a:0 > 0? a:1 : 4)
    let hardWidth = (a:0 > 1? a:2 : 8)
    let &l:tabstop=hardWidth
    let &l:softtabstop=softWidth
    let &l:shiftwidth=softWidth
    let &l:expandtab=1
endfun

" Searching options
set ignorecase   " Ignore case when searching
set smartcase    " See :help smartcase (trust me, it's useful)
set incsearch    " Incremental search
set hlsearch     " Highlight 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>

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

" Miscellaneous stuff...
set backspace=indent,eol,start " Better backspacing
set ruler           " Show a ruler along the bottom of the screen
set lazyredraw      " 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
" set relativenumber  " Relative jump numbers up the side

" Folding options
set foldmethod=marker

" Formatting options
"autocmd BufNewFile,BufRead * setlocal formatoptions+=cqn
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, ftplugin/rst.vim
set formatlistpat=^\\s*\\(\\(\\d\\+\\\)[\\]:.)}\\t\ ]\\\)\\s*

" 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')
endif

" 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

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

" Remap <m-.> to next-change-location and <m-,> to previous-change-location
noremap <esc>, <c-o>
noremap<c-o>
noremap <esc>. <c-i>
noremap<c-i>

" 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 convenience 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 = gt
map - gT

" 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/**
endif

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

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

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

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

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

if has("mouse")
    set mouse=a
endif

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

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

" Things to ignore while spell checking:
" - CamelCase words
" - URLs http://asdf.com/asdf
" - paths /asdf/adfa/dsfa
" - emails asdf@asdf.com
" - backslash-escaped characters \t \n
fun! AddSpellIgnore()
    syn match SpellIgnoreCamel /\<[A-Z][a-z]\+[A-Z].\{-}\>/ contains=@NoSpell transparent
    syn match SpellIgnorePath /[^ \t'"<>]*\/[^ \t'"<>]*/ contains=@NoSpell transparent
    syn match SpellIgnoreEmail /[a-zA-Z][^ \t]*@[^ \t]*\.[a-z]\{,3}\>/ contains=@NoSpell transparent
    syn match SpellIgnoreEscaped /\\[a-zA-Z]/ contains=@NoSpell transparent
    syn match SpellIgnoreFile /[a-zA-Z][^ \t'"<>]*\.[a-zA-Z]\+/ contains=@NoSpell transparent
    syn cluster Spell add=SpellIgnoreCamel,SpellIgnorePath
    syn cluster Spell add=SpellIgnoreEmail,SpellIgnoreEscaped, SpellIgnoreFile
endfun
" autocmd BufRead,BufNewFile * :call AddSpellIgnore()

" Don't highlight '$(...)' as an error in shell scripts
let g:is_posix = 1

" Use :Term to open a terminal
fun! Term()
   !~/bin/term  "%:p:h"
endfun
command! Term call Term()


" Enable perdy 256 color mode
" set t_Co=256
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.