Please bear with us as we work to restore functionality to dotfiles.org.
You might find some reusable gems in here.
" $Id: vimrc 3241 2008-09-27 04:37:42Z 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 autoindent
set background=light
set backspace=indent,eol,start " allow backspace over anything in insert mode
set nocompatible
" comments option settings from http://stripey.com/vim/vimrc.html
" lots of other great help at http://stripey.com/vim/
" get rid of the default style of C comments; define a bullet list
" style for single stars (like already is for hyphens):
set comments-=s1:/*,mb:*,ex:*/
set comments+=fb:*
" treat lines starting with a quote mark as comments (for `Vim' files, such as
" this very one!), and colons as well so that reformatting usenet messages from
" `Tin' users works OK:
set comments+=b:\"
set comments+=n::
set dictionary+=/usr/share/dict/words
" 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
" Quite handy when editing formatted plain text, like bullet lists, etc.
" See the fo-table help page for more info on possible options.
"set formatoptions
set hlsearch
set ignorecase
set incsearch
set matchtime=2
" set matchpairs (which patterns can be matched with %)
set matchpairs=(:),{:},[:],<:>
set mousemodel=popup
set nojoinspaces
" 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=4
set nostartofline
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
set wildmode=list:longest
" 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 ]
" start a new vimoutliner file (mnemonic is New Notes)
nmap nn 80i-ovim: ft=vo_basekO
nmap cz 25i-a8<25a-o25i-a>825a-o
" 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
" experimenting with TextMate-like snippets plugin
" http://www.vim.org/scripts/script.php?script_id=2086
let g:CodeSnippet_no_default_mappings = 1
map CodeSnippet_forward
imap CodeSnippet_forward
map CodeSnippet_backward
imap CodeSnippet_backward
" Language-specific settings {{{1
" Simple filetype detection {{{2
" recognize TextForge files and use html-style syntax highlighting
" (override setting in $VIMRUNTIME/filetype.vim)
autocmd BufNewFile,Bufread *.tf setfiletype 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 BufNewFile *.pl 0r ~/.vim/templates/newperlfile
autocmd BufRead,BufNewFile Rakefile setfiletype ruby
autocmd BufRead,BufNewFile *.rhtml setfiletype eruby
" FreeMarker
autocmd BufNewFile,BufRead *.ftl setfiletype html
" Complex filetype adaptations {{{2
" 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
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
" Vimoutliner
autocmd BufRead,BufNewFile *.otl call VimOutlinerSettings()
function s:VimOutlinerSettings()
set filetype=vo_base
set foldcolumn=0
endfunction
autocmd BufNewFile,Bufread mig.cf call MigConfSettings()
function s: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 \%\\ {\public static void main(String args[]) {\}\}\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 ?>15hi
iab udd 9hi
set indentexpr=
set sw=4
set ts=4 " temporary... for Knowledge Tree
endfunction
autocmd BufNewFile *.pl call SetupNewPerlFile()
function s:SetupNewPerlFile()
execute "normal i#!/usr/bin/perl -w\\xiuse strict;\\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
" Not in a FileType function like the other filetype-specific mappings since
" I think this must be set *before* SQL bits are loaded
let g:omni_sql_no_default_maps = 1
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
" Mifos source code settings
autocmd BufNewFile,Bufread */svn/mifos* call MifosSettings()
function s:MifosSettings()
set noexpandtab " don't use spaces to indent
set nosmarttab " don't ever use spaces
set tabstop=4 " most Mifos source files look good with this
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 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
set tw=72
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
" before writing word lists, put them in order
autocmd BufWritePre *word*.txt %sort
endfunction
" 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
autocmd FileType tex call TeXfileSettings()
function s:TeXfileSettings()
"set formatoptions+=a
set makeprg=make
endfunction
" for files encrypted using ccrypt(1)
augroup CPT
au!
" decrypt before reading
au BufReadPre *.cpt set bin viminfo= noswapfile
" decrypted; prepare for editing
au BufReadPost *.cpt let $VIMPASS = inputsecret("Password: ")
au BufReadPost *.cpt %!ccrypt -cb -E VIMPASS
au BufReadPost *.cpt set nobin
" encrypt
au BufWritePre *.cpt set bin
au BufWritePre *.cpt %!ccrypt -e -E VIMPASS
" encrypted; prepare for continuing to edit the file
au BufWritePost *.cpt silent undo | set nobin
augroup END
" Miscellaneous {{{1
" EXPORTING TO HTML... (see ':he 2html')
" 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