" $Id: vimrc 2358 2007-07-31 15:01:25Z adam $
" General options {{{1
filetype plugin indent on
syntax on
" These are in alphabetical order, except that the characters 'no' are ignored
" if they appear at the beginning of an option name.
set background=light
set backspace=indent,eol,start " allow backspace over anything in insert mode
set nocompatible
set dictionary+=/usr/share/dict/words
set noequalalways
" need to rethink default of 'expandtab/noexpandtab'.
" expandtab is nice for this:
" any/all source code (java/c/python/perl/vim/php/...)
" noexpandtab is better for this:
" vimoutliner files
" word lists for GRE prep
set expandtab
set hlsearch
set ignorecase
set incsearch
set matchtime=2
" set matchpairs (which patterns can be matched with %)
set matchpairs=(:),{:},[:],<:>
set mousemodel=popup
" allegedly, backticks are also allowed in values
" ...so, maybe something like 'set printdevice=`cat /etc/printcap`'
"set printdevice=cookie
" see :help 'statusline' for format of printheader (note spaces need escaping)
set printheader=%<%f\ %y%=Adam\ Monsen\ \ --\ \ Page\ %N\ (%P)
"set printheader=%<%f\ %y%=Page\ %N\ (%P)
set printoptions=paper:letter,duplex:off,number:n,left:10mm,portrait:y
" good settings for XML
"set printoptions=paper:letter,duplex:off,number:n,left:10mm,portrait:n,header:0
set ruler
set showcmd " display incomplete commands
set showfulltag " show prototype when completing words using tags file
set showmatch
set smarttab
set smartindent
set shiftwidth=2
set suffixes=.bak,~,.o,.h,.info,.swp,.obj,.class
set title
set ttyfast " we have a fast terminal connection
set ttyscroll=3
set visualbell
set virtualedit=
set wildmenu
" Functions {{{1
" F8 is my magic color switcher...
" toggles syntax highlighting for light/dark backgrounds
function! s:Swapcolor()
if exists("g:syntax_on")
syntax off
else
" see eval.txt in the vim helpfiles...
" &background checks the background option
if &background == 'light'
set background=dark
elseif &background == 'dark'
set background=light
endif
syntax on
endif
endfunction
" from http://www.vim.org/tips/tip.php?tip_id=384
function! s:SwitchSourceHeader()
if (expand ("%:t") == expand ("%:t:r") . ".cpp")
find %:t:r.h
else
find %:t:r.cpp
endif
endfunction
" Key Mappings {{{1
set pastetoggle=<F2>
map <F3> :set number!<CR>
map <F4> :set wrap!<CR>
map <F5> :set list!<CR>
nmap <F6> :make<CR>
" map F8 to switch on and off syntax highlighting
map <F8> :call <SID>Swapcolor()<CR>
" gf usually just opens the file in the same window
map gf :split <cfile><CR>
" throw in the date, ala [ Sun Sep 26 22:41:43 PDT 2004 ]
nmap <Leader>dt a[^[:r !date<CR>kJ$a ]^[
" most CVS stuff replaced with http://vim.org/scripts/script.php?script_id=90
augroup CVSCommand
" let q 'go back' after a CVSDiff or whatnot (see :help cvscommand-events)
au CVSCommand User CVSBufferCreated silent! nmap <unique> <buffer> q :bwipeout<cr>
let CVSCommandDiffOpt = 'wbBu'
let CVSCommandEdit = 'split'
augroup END
augroup SVNCommand
" allow single 'q' keypress to close a SVNCommand buffer/window
au SVNCommand User SVNBufferCreated silent! nmap <unique> <buffer> q :bwipeout<cr>
let SVNCommandEdit = 'split'
augroup END
" Language-specific settings {{{1
" some C shortcuts
autocmd FileType c call <SID>CProgSettings()
function! s:CProgSettings()
iabbrev stdio #include <stdio.h>
iabbrev stdlib #include <stdlib.h>
iabbrev main_ int<CR>main (void)<CR>{<CR>return 0;<CR>}
" used to be useful for test programs, now I almost always use a Makefile
" ...maybe a stock Makefile that just compiles any .c files to a.out would
" be nice for simple, small tests
"set makeprg=gcc\ -Wall\ -pedantic-errors\ -ansi\ -g\ %
set foldmethod=syntax
" syn region Block start="{" end="}" transparent fold
"set foldtext=substitute(getline(v:foldstart),'{.*','{...}','')
"syn region cFuncBody
" \ start='^{\ze\s*\%(\n}\@!\%(.*\)\@>\)*\n}\s*$'
" \ end='^}\s*$'
" \ fold transparent
set shiftwidth=4
nmap ,s :call <SID>SwitchSourceHeader()<CR>
endfunction
" for some reason this must be outside of CProgSettings()
let g:c_space_errors = 1
" some C++ shortcuts
autocmd FileType cpp call <SID>CppProgSettings()
function! s:CppProgSettings()
"set makeprg=g++\ -ansi\ -pedantic\ -Wall\ -g\ %
nmap ,s :call <SID>SwitchSourceHeader()<CR>
endfunction
augroup filetypedetect
" recognize TextForge files and use html-style syntax highlighting
" (override setting in $VIMRUNTIME/filetype.vim)
autocmd BufNewFile,Bufread *.tf set filetype=tforge
autocmd! BufRead,BufNewFile *inputrc setfiletype readline
autocmd! BufNewFile,Bufread mig.cf setfiletype html
autocmd! BufNewFile,Bufread *.t setfiletype perl
autocmd! BufNewFile,Bufread *.jad setfiletype java
autocmd! BufNewFile,Bufread *.jspf setfiletype jsp
" cause javaclassfile.vim ftplugin to be executed, which uses jad
" to decompile and display on the fly
autocmd! BufNewFile,Bufread *.class setfiletype javaclassfile
autocmd! BufRead,BufNewFile Rakefile setfiletype ruby
autocmd! BufRead,BufNewFile *.rhtml setfiletype eruby
autocmd BufNewFile,Bufread mig.cf call <SID>MigConfSettings()
autocmd! BufRead,BufNewFile *.otl setfiletype vo_base
set shiftwidth=4
augroup end
function! MigConfSettings()
set filetype=html
" add some autocommands/mappings/whatever here
endfunction
autocmd BufNewFile *.java call <SID>NewJavaFileTemplate()
function! s:NewJavaFileTemplate()
" inserts boilerplate code for a new Java file
execute "normal iclass \<C-R>%\<C-W>\<C-W>\n{\npublic static void main(String args[])\n{\n}\n}\<C-C>kk"
endfunction
autocmd FileType java call <SID>JavaPrgSettings()
function! s:JavaPrgSettings()
" iabbrev main public static void main(String args[])
iabbrev lD if (isLoggingDebug())<CR>{<CR>logDebug("");<CR>}^[kf"li
iabbrev lI if (isLoggingInfo())<CR>{<CR>logInfo("");<CR>}^[kf"li
iabbrev lW if (isLoggingWarning())<CR>{<CR>logWarning("");<CR>}^[kf"li
iabbrev lE if (isLoggingError())<CR>{<CR>logError("");<CR>}^[kf"li
iabbrev print System.out.println
iabbrev warn System.err.println
"set makeprg=javaMakeCompile\ %:r
let g:java_highlight_java_lang_ids=1
let g:java_highlight_debug=1
" Disable // comment auto-insertion behavior
" (from http://vimdoc.sourceforge.net/cgi-bin/vimfaq2html3.pl#27.7)
set comments=sr:/*,mb:*,el:*/
endfunction
autocmd FileType python call <SID>PythonPrgSettings()
function! s:PythonPrgSettings()
set sw=4 ts=4 et
nmap <Leader>pd :!pydoc <cword><CR>
set makeprg=python\ -tt\ %
" cindent seems to make comments on a new line stay on the current column
" and this is what I want.
set cindent
set comments=:#
" not in plugin dir because I rarely want folds
"so ~/.vim/python_fold.vim
nmap <Leader>pdb oimport pdb; pdb.set_trace()^[
endfunction
autocmd FileType php call <SID>PhpPrgSettings()
function! s:PhpPrgSettings()
iab pdd ?><pre><?php print_r() ?></pre><?php ^[15hi
iab udd <pre><?php print_r() ?></pre>^[9hi
set indentexpr=
set sw=4
set ts=4 " temporary... for Knowledge Tree
endfunction
" autocmd BufNewFile *.pl 0r ~/.vim/templates/newperlfile
autocmd BufNewFile *.pl call <SID>SetupNewPerlFile()
function! s:SetupNewPerlFile()
execute "normal i#!/usr/bin/perl -w\n\<C-C>xiuse strict;\n\<C-C>xo"
endfunction
autocmd FileType perl call <SID>PerlProgSettings()
autocmd FileType tforge call <SID>PerlProgSettings()
function! s:PerlProgSettings()
set cindent
" perl comments start with #, anywhere on the line
set comments=:#
set cinkeys-=0#
" If you want complex things like '@{${"foo"}}' to be parsed:
let g:perl_extended_vars = 1
let g:perl_sync_dist = 100
" See ':help syntax'
let g:perl_fold = 1
set foldlevelstart=1
" handy abbreviations
iab udd use Data::Dumper; print Dumper ();^[hi
iab ddd use Data::Dumper; die Dumper ();^[hi
iab wdd use Data::Dumper; warn Dumper ();^[hi
set makeprg=perl\ -w\ %
nmap <Leader>pf :!perldoc -f <cword><CR>
nmap <Leader>pd :e `perldoc -ml <cword>`<CR>
endfunction
autocmd FileType xml call <SID>XMLFileSettings()
function! s:XMLFileSettings()
set foldmethod=syntax
"use the left margin to show folds
"set foldcolumn=8
set foldlevel=1
endfunction
autocmd FileType changelog call <SID>ChangeLogSettings()
function! s:ChangeLogSettings()
let g:changelog_username = 'Adam Monsen <haircut@gmail.com>'
endfunction
autocmd BufNewFile,Bufread NEWS call <SID>NewsFileSettings()
function! s:NewsFileSettings()
set tw=72
endfunction
" the yodel guys use tabs instead of spaces
autocmd BufNewFile,Bufread */yodel/* call <SID>YodelSettings()
function! s:YodelSettings()
set noexpandtab " don't use spaces to indent
set nosmarttab " don't ever use spaces
endfunction
autocmd BufNewFile,Bufread *akefile call <SID>MakefileSettings()
function! s:MakefileSettings()
set noexpandtab " don't use spaces to indent
set nosmarttab " don't ever use spaces, not even at line beginnings
endfunction
" Editing files with comma-separated values has never been so fun!
" All this next stanza does is allow one to use F9 and F10 to highlight
" the previous and next columns, respectively. This makes editing CSV
" in Vim much more convenient than visually matching up columns.
autocmd BufNewFile,Bufread *csv call <SID>CSVSettings()
function! s:CSVSettings()
let b:current_csv_col = 0
" inspired by Vim tip #667
function! s:CSV_Highlight(x)
if b:current_csv_col == 0
match Keyword /^[^,]*,/
else
execute 'match Keyword /^\([^,]*,\)\{'.a:x.'}\zs[^,]*/'
endif
execute 'normal ^'.a:x.'f,'
endfunction
" start by highlighting something, probably the first column
call <SID>CSV_Highlight(b:current_csv_col)
function! CSV_HighlightNextCol()
let b:current_csv_col = b:current_csv_col + 1
call <SID>CSV_Highlight(b:current_csv_col)
endfunction
function! CSV_HighlightPrevCol()
if b:current_csv_col > 0
let b:current_csv_col = b:current_csv_col - 1
endif
call <SID>CSV_Highlight(b:current_csv_col)
endfunction
map <F9> :call <SID>CSV_HighlightPrevCol()<CR>
map <F10> :call <SID>CSV_HighlightNextCol()<CR>
endfunction
autocmd FileType spec call <SID>SpecfileSettings()
function! s:SpecfileSettings()
let g:packager = 'Adam Monsen <haircut@gmail.com>'
let g:spec_chglog_format = '%a %b %d %Y Adam Monsen <haircut@gmail.com>'
let g:spec_chglog_release_info = 1
endfunction
" special journal settings
autocmd BufNewFile,Bufread journal*.txt call <SID>JournalSettings()
function! s:JournalSettings()
setlocal spell spelllang=en_us
endfunction
" Adapt to GRE word study lists
autocmd BufNewFile,Bufread */gre_prep/*word*.txt call <SID>QuizDBSettings()
function! s:QuizDBSettings()
set noexpandtab
set spell spelllang=en_us
set nowrap
set textwidth=0
" dict is provided by the dictd package
set keywordprg=dict\ -P\ 'less\ --dumb'
endfunction
" before writing word lists, put them in order
autocmd BufWritePre */gre_prep/*word*.txt %sort
" Some of the HTML-specific settings require the HTML/XHTML editing macros
" provided by http://vim.org/scripts/script.php?script_id=453
let g:html_tag_case = 'lowercase'
" HTMLSettings function ready for custom settings...
"autocmd FileType html call <SID>HTMLSettings()
"function! s:HTMLSettings()
"endfunction
" Miscellaneous {{{1
" EXPORTING TO HTML... (see ':he 2html')
" For some reason, the following line only works if it's set down here at the
" bottom of this file!
set formatoptions+=nor
" Edit another file in the same directory as the current file
" uses expression to extract path from current file's path
" (thanks Douglas Potts)
if has("unix")
map ,e :e <C-R>=expand("%:p:h") . "/" <CR>
else
map ,e :e <C-R>=expand("%:p:h") . "\" <CR>
endif
" Shell Script Goodies {{{2
" see ':he syntax' for more info
" Any shell scripts I edit will most likely be Bash
let g:is_bash = 1
" allow for heredocs, etc.
let g:sh_fold_enabled = 1
" Final thoughts, modeline, etc. {{{1
set secure
" vim:foldmethod=marker