" $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= map :set number! map :set wrap! map :set list! nmap :make " map F8 to switch on and off syntax highlighting map :call Swapcolor() " gf usually just opens the file in the same window map gf :split " throw in the date, ala [ Sun Sep 26 22:41:43 PDT 2004 ] nmap dt a[:r !datekJ$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 q :bwipeout 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 q :bwipeout let SVNCommandEdit = 'split' augroup END " Language-specific settings {{{1 " some C shortcuts autocmd FileType c call CProgSettings() function! s:CProgSettings() iabbrev stdio #include iabbrev stdlib #include iabbrev main_ intmain (void){return 0;} " 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 SwitchSourceHeader() endfunction " for some reason this must be outside of CProgSettings() let g:c_space_errors = 1 " some C++ shortcuts autocmd FileType cpp call CppProgSettings() function! s:CppProgSettings() "set makeprg=g++\ -ansi\ -pedantic\ -Wall\ -g\ % nmap ,s :call SwitchSourceHeader() 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 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 NewJavaFileTemplate() function! s:NewJavaFileTemplate() " inserts boilerplate code for a new Java file execute "normal iclass \%\\\n{\npublic static void main(String args[])\n{\n}\n}\kk" endfunction autocmd FileType java call JavaPrgSettings() function! s:JavaPrgSettings() " iabbrev main public static void main(String args[]) iabbrev lD if (isLoggingDebug()){logDebug("");}kf"li iabbrev lI if (isLoggingInfo()){logInfo("");}kf"li iabbrev lW if (isLoggingWarning()){logWarning("");}kf"li iabbrev lE if (isLoggingError()){logError("");}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 PythonPrgSettings() function! s:PythonPrgSettings() set sw=4 ts=4 et nmap pd :!pydoc 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 pdb oimport pdb; pdb.set_trace() endfunction autocmd FileType php call PhpPrgSettings() function! s:PhpPrgSettings() iab pdd ?>
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 SetupNewPerlFile() function! s:SetupNewPerlFile() execute "normal i#!/usr/bin/perl -w\n\xiuse strict;\n\xo" endfunction autocmd FileType perl call PerlProgSettings() autocmd FileType tforge call 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 pf :!perldoc -f nmap pd :e `perldoc -ml ` endfunction autocmd FileType xml call 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 ChangeLogSettings() function! s:ChangeLogSettings() let g:changelog_username = 'Adam Monsen ' endfunction autocmd BufNewFile,Bufread NEWS call NewsFileSettings() function! s:NewsFileSettings() set tw=72 endfunction " the yodel guys use tabs instead of spaces autocmd BufNewFile,Bufread */yodel/* call 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 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 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 CSV_Highlight(b:current_csv_col) function! CSV_HighlightNextCol() let b:current_csv_col = b:current_csv_col + 1 call 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 CSV_Highlight(b:current_csv_col) endfunction map :call CSV_HighlightPrevCol() map :call CSV_HighlightNextCol() endfunction autocmd FileType spec call SpecfileSettings() function! s:SpecfileSettings() let g:packager = 'Adam Monsen ' let g:spec_chglog_format = '%a %b %d %Y Adam Monsen ' let g:spec_chglog_release_info = 1 endfunction " special journal settings autocmd BufNewFile,Bufread journal*.txt call JournalSettings() function! s:JournalSettings() setlocal spell spelllang=en_us endfunction " Adapt to GRE word study lists autocmd BufNewFile,Bufread */gre_prep/*word*.txt call 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 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 =expand("%:p:h") . "/" else map ,e :e =expand("%:p:h") . "\" 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