brendano /.vimrc

" Brendan O'Connor's .vimrc - dotfiles.org/~brendano - brenocon at gmail
" for Vim 6.x, 7.x
" make sure to liberally use :help TOPIC
" and get .vim/ from (at the moment) brendano.users.sonic.net/vim.tgz

set exrc

if filereadable(expand("$VIM/runtime/colors/macvim.vim"))
  colo macvim
elseif filereadable(expand("$HOME/.vim/colors/brendano.vim"))
  colo brendano
elseif has("gui_running")
  colo zellner
"  colo murphy
else
"  colo evening
  colo zellner
end

set background=light
"let xterm16_colormap    = 'light'
"let xterm16_brightness  = 'default'
"colo xterm16

" ------------------------ General Options -----------------------------

" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

set encoding=utf8

" Gui options
" set guioptions=aigmrL "plays around with menu/toolbars
set guioptions=agimrLt
" unix, windows, mac, etc all want different names
" set guifont=Courier_New:h10:cANSI 
" set guifont=monospace_12
" set guifont=-misc-fixed-medium-r-normal-*-*-130-*-*-c-*-iso8859-15
" set guifont=-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1

set mouse=a  " For mouse support on a good terminal (xterm, putty, iterm, *not*
             " mac terminal by default)
" set term=xterm-color  " normally is set by TERM but sometimes vim is smarter
                        " with an override

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

" set autoindent
set backup		" keep a backup file
set history=1000	" keep 50 lines of command line history
set ruler		" show the cursor position all the time
set showcmd		" display incomplete commands
set incsearch		" do incremental searching
set ignorecase smartcase
set scrolloff=2
set showmatch           " parenthesis matching
syntax on
set hlsearch

" tab completion for e.g. :e is awesome with these
set wildmenu
"set wildmode=list:longest,full
set wildmode=list:longest

set hidden   " have multiple buffers without saving all the time
set title

" Tabbing world... I *think* this is the best compromise between all
" the competing incompatible standards out there...
set expandtab      " spaces not tabs
set tabstop=8      " the one true tab size
set shiftwidth=2   " size for auto/smartindent
set softtabstop=2  " when you press  it moves by this much
set shiftround
set smartindent    " :help says needs to have autoindent but doesn't seem so

" Don't put *~ backup files and .*.swp swap files in the current dir - instead
" put all in ~/.bak
set backupdir=~/.bak,.,~
set directory=~/.bak,.,~

if version>=700
  set tags+=$PWD/tags  " necessary since chdir keeps changing
endif

if exists('+autochdir')
  " so :e is relative to current file
  set autochdir
else
  autocmd BufEnter * silent! lcd %:p:h:gs/ /\\ /
endif

let g:explHideFiles='^\.,pyc$,.pyo$,.o$,.obj$'

" --------------------  Key Redefinitions ------------------------

" emacs/cocoa-style keybindings
noremap  p
noremap  ^
noremap  $
noremap  x

inoremap  D
inoremap  p
inoremap  ^
inoremap  $
inoremap  x

" Ctrl-style scrolling (stationary cursor)
noremap  
noremap  
noremap  
noremap  

" Arrow keys to screen lines, not physical lines.  
" [jk default behavior preserved.]
noremap  gk
noremap  gj

" Tabs
" D- is the mac command key in gvim.  Was trying to emulate safari
" keybindings, not sure how successful
noremap  :tabn
noremap  :tabp
noremap  :tabe
noremap  :tabclose
imap  :tabn
imap  :tabp

" Don't use Ex mode, use Q for formatting
map Q gq

" F-Keys
" For the upper-left-cramped IBM thinkpad keyboard... no more F1 -> help
map  
imap  
vmap  

" Compiler integration -- past F12 inteded for left side on a Sun keyboard
" they used to have in dear old sweet hall.
map  :make
" These work with :grep matches, too
map  :cp
map  :cn
map  :cc
map  :colder
map  :cnewer

" Buffer moving
map  :bp
map  :bn

" " vtreeexplorer.vim  http://www.vim.org/scripts/script.php?script_id=184
" "map \te :vsp:vertical resize 30:VTreeExplore
" let g:treeExplVertical = 1
" let g:treeExplWinSize = 30                                                                                            
map \te :VSTreeExplore

" NERD tree is the best speedbar I've seen - it makes vim dramatically more
" useful for multi-file projects.
" http://www.vim.org/scripts/script.php?script_id=1658
map \ne :NERDTreeToggle
let NERDTreeMapActivateNode=''

" buffer explorer is like emacs electric-buffer-list -- it uses most recently
" visited sort order, so you can hit three close-by keystrokes:
"   ;  
" to swap with the most recently visited file.  This is the only multi-file
" editing feature missing from eclipse and textmate.
"
map ; \be

" tComment.vim  http://www.vim.org/scripts/script.php?script_id=1173
" doesnt have visual mode commenting so we add it
vnoremap gc :TComment
vnoremap ,c :TComment
nmap ,c gcc

" really basic commenting -- vim.org tip #271
" lhs comments 
map ,# :s/^\s*/\0#/:nohlsearch 
map ,/ :s/^\s*/\0\/\//:nohlsearch 
"map ,/ :s/^/\/\/ /:nohlsearch 
map ,> :s/^\s*/\0>/:nohlsearch 
map ," :s/^\s*/\0\"/:nohlsearch 
map ,% :s/^\s*/\0%/:nohlsearch 
map ,! :s/^\s*/\0!/:nohlsearch 
map ,; :s/^\s*/\0;/:nohlsearch 
map ,- :s/^\s*/\0-- /:nohlsearch 
"map ,c :s/^\s*\/\/\\|^--\\|^> \\|^[#"%!;]//:nohlsearch 
" wrapping comments 
map ,* :s/^\(.*\)$/\/\* \1 \*\//:nohlsearch 
map ,( :s/^\(.*\)$/\(\* \1 \*\)/:nohlsearch 
map ,< :s/^\(.*\)$//:nohlsearch 
map ,d :s/^\([/(]\*\\|\)$/\2/:nohlsearch 
"
"" UN-commenting -- just kill first token on line, works only for lhs comments
"map ,, :s/\s*\S*\s\(.*\)/\1/:nohlsearch
"  "map , :s/^\(\s*\)\(\/\/\|[#%!><]\)/\1/:nohlsearch

" gotta double backslash the pipe because of "map"
map , :s/^\(\s*\)\([#"%!;<>]\\|\/\/\)/\1/:nohlsearch

"map ,m :s/.*/"\0"/:nohlsearch

" Un-comment
map , :s/^"\(.*\)"$/\1/:nohlsearch

ab pf printf(


" Make p in Visual mode replace the selected text with the "" register.
vnoremap p :let current_reg = @"gvs=current_reg

" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp


" Name completion with tab.  Need to change this once I figure out how, so
" you can use the tab button more often.

" function! CleverTab()
"    if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
"       return "\"
"    else
"       return "\"
" endfunction
" inoremap  =CleverTab()

" crappy hacky title setting
function! SetTitle(newtitle)
  let zshcmd='\e]0;' . a:newtitle . '\a'
  execute "silent ! print -Pn \"" . zshcmd ."\""
  "" This should be the iterm escape sequence, but doesnt seem to work
  "let zshcmd='\e]1;' . a:newtitle . '\a'
  "execute "silent ! print -Pn \"" . zshcmd ."\""
  redraw!
endfunction


"   augroup mkd
"   augroup END

if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  au FileType text setlocal textwidth=78
  au FileType make setlocal noexpandtab

  " 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).
  autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \   exe "normal g`\"" |
    \ endif

  " markdown filetype file
  au BufRead *.md,*.mkd  set ai formatoptions=tcroqn2 comments=n:>
  " au FileType python source ~/.vim/python.vim
  augroup END
else
  set autoindent		" always set autoindenting on
endif " has("autocmd")

" if filereadable(expand("$HOME/.vim/plugin/vimbuddy.vim"))
"   set statusline+=\ %{VimBuddy()}          " vim buddy
" endif

" vim:sw=2:sts=2:noet: