" .vimrc
" cayla fauver <cayla@wehavenoproduct.com>
" Created: Sat Sep 17, 2005  08:02PM
" Last modified: Wed Jun 11, 2008 02:50PM
" Description: a work in progress
"

au!
if has('syntax') && (&t_Co > 2)
  syntax on
endif

if &term =~ 'xterm'
  if $COLORTERM == 'gnome-terminal'
    execute 'set t_kb=' . nr2char(8)
    fixdel
    set t_RV=
  elseif $COLORTERM == ''
    execute 'set t_kb=' . nr2char(8)
    fixdel
  endif
endif

colorscheme desert
set nocompatible

set autoindent
set background=dark
set backspace=eol,start,indent
set comments+=b:#
set comments+=b:\"
set comments+=fb:*
set comments+=n::
set comments+=s:/*,mb:**,ex:*/
set comments-=s1:/*,mb:*,ex:*/
set directory=~/tmp
set expandtab
set formatoptions+=ro
set formatoptions-=t
set gdefault
set history=50
set ignorecase
set incsearch
set laststatus=2
set matchpairs+=<:>
set mouse=a
set nobackup
set nowrap
set shiftwidth=4
set shortmess+=r
set showcmd
set showmatch
set showmode
set smartcase
set smartindent
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
set tabstop=4
set textwidth=72
set title
set undolevels=50
set viminfo=/10,'10,r/mnt/zip,r/mnt/floppy,f0,h,\"100
set whichwrap=h,l,~,[,]
set wildmode=list:longest,full

ab cef cayla fauver <cayla@wehavenoproduct.com>
ab fh # <C-R>%<CR>cayla fauver <cayla@wehavenoproduct.com><CR>Created: <ESC>"=strftime("%a %b %d, %Y %I:%M%p")<CR>p<ESC>oLast modified: <CR>Description:
ab pfh #!/usr/bin/perl -w<CR> <C-R>%<CR>cayla fauver <cayla@wehavenoproduct.com><CR>Created: <ESC>"=strftime("%a %b %d, %Y %I:%M%p")<CR>p<ESC>oLast modified: <CR>Description:
ab pyh #!/usr/bin/python<CR> <C-R>%<CR>cayla fauver <cayla@wehavenoproduct.com><CR>Created: <ESC>"=strftime("%a %b %d, %Y %I:%M%p")<CR>p<ESC>oLast modified: <CR>Description:

filetype on
augroup filetype
  au BufNewFile,BufRead *.txt,README*,mutt*[0-9] set filetype=human
augroup END

au FileType c,cpp,java          let b:comment_leader = '// '
au FileType c,cpp,slang         set cindent
au FileType css                 set smartindent
au FileType haskell,vhdl,ada    let b:comment_leader = '-- '
au FileType html                set formatoptions+=tl
au FileType html,css            set noexpandtab tabstop=2
au FileType human               set noautoindent nosmartindent formatoptions-=r textwidth=72
au FileType make                set noexpandtab shiftwidth=8
au FileType perl                set smartindent
au FileType sh,make,perl,python let b:comment_leader = '# ' 
au FileType tex                 let b:comment_leader = '% '
au FileType vim                 let b:comment_leader = '" ' 

au BufRead *.py                 set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class

au BufWrite *.pl ks|call LastMod()|'s
au BufWrite *rc ks|call LastMod()|'s

noremap <Space> <PageDown>
noremap <BS> <PageUp>
noremap <C-Tab> :bn<CR>
noremap <S-C-Tab> :bp<CR>
noremap Q gqap
map Q gqGgg

noremap <silent> ,c :<C-B>sil <C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:noh<CR> 
noremap <silent> ,u :<C-B>sil <C-E>s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:noh<CR> 

nnoremap <F1> :help<Space>
vmap <F1> <C-C><F1>
omap <F1> <C-C><F1>
map! <F1> <C-C><F1>

let IspellLang = 'american'
let PersonalDict = '~/.ispell_' . IspellLang
execute 'set dictionary+=' . PersonalDict
set dictionary+=/usr/dict/words
set complete=.,w,k
set infercase
execute 'nnoremap \si :w<CR>:!ispell -x -d ' . IspellLang . ' %<CR>:e<CR><CR>'
nmap <F5> \si
set pastetoggle=<F6>
map <F11> :!wc -w %; sleep 3 <Enter><Enter>
map <F12> :TOhtml<CR>:wq<CR>

" FUNCTIONS

" Search the first 20 lines for Last modified: and update the current datetime. 
function! LastMod()
    if line("$") > 20 
let l = 20 
    else 
let l = line("$") 
    endif 
    exe "1," . l . "g/Last modified: /s/Last modified: .*/Last modified: " . 
\ strftime("%a %b %d, %Y %I:%M%p") 
endfun