" Generic functions that I like. Some I wrote, many I stole. :) " ====================================================================== fun! Error(msg) echohl ErrorMsg echo "ERROR: " . msg echohl None endfun " ============================================================================= function! ShowManPage(whichpage) " ShowManPage: function to show a man page " the parameter is the page to show " ----------------------------------------------------------------------------- " modify the shortmess option: " A don't give the "ATTENTION" message when an existing swap file is " found. set shortmess+=A " if a buffer already exists delete it if bufexists("/manual\ page") bd! /manual\ page endif " create a new one new /manual\ page " read the man page in execute 'r!man ' a:whichpage '| col -b' " highlight it "source ~phil/.vim/manpages.vim "source $VIM/syntax/manpages.vim source $VIMRUNTIME/syntax/man.vim " set some options set ts=8 set nomodified " go to the beginning of the buffer execute "normal 1G" " restore the shortmess option set shortmess-=A endfunction "ShowManPage " ============================================================================= function! ShowManPageCursor() " functions to show a man page " - ShowManPageCursor: of the word under the cursor " - ShowManPageInput: ask the user which page " ----------------------------------------------------------------------------- " get the word under the cursor let whichpage = expand("") call ShowManPage(whichpage) endfunction "ShowManPageCursor " ============================================================================= function! ShowManPageInput() " ----------------------------------------------------------------------------- " ask the user which page he wants let whichpage = input("man: ") " do nothing if the user didn't enter a manpage if whichpage != "" call ShowManPage(whichpage) endif endfunction "ShowManPageInput " ============================================================================= function! ReadCommandInBuffer(bufferName, cmdName) " ReadCommandInBuffer " - bufferName is the name which the new buffer with the command results " should have " - cmdName is the command to execute " ----------------------------------------------------------------------------- " modify the shortmess option: " don't give the "ATTENTION" message when an existing " swap file is found. set shortmess+=A " get the name of the current buffer let currentBuffer = bufname("%") " if a buffer with the name rlog exists, delete it if bufexists(a:bufferName) execute 'bd! ' a:bufferName endif " create a new buffer execute 'new ' a:bufferName " execute the rlog command execute 'r!' a:cmdName ' ' currentBuffer set nomodified " go to the beginning of the buffer execute "normal 1G" " restore the shortmess option set shortmess-=A endfunction "ReadCommandInBuffer " =========================================================================== fu! Delineate(line_char) " Delinate code, start out a separation marker from current indent " and extend out to textwidth " --------------------------------------------------------------------------- if a:line_char == "" let line_char = "-" else let line_char = a:line_char endif " Use this to get current indent exe 'normal ox' let curcol=col(".") let currow=line(".") " Default to 80 char width if no textwidth if &tw < 1 let numchars = 80 - curcol else let numchars= &tw - curcol endif " Init tmpstr so it has indent in it let linestr = getline(currow) let tmpstr = strpart(linestr, 0, strlen(linestr)-1) let charcnt = 1 while charcnt <= numchars let tmpstr = tmpstr.line_char let charcnt = charcnt + 1 endw call setline(currow, tmpstr) endfu " Bind ShowManPageCursor to K map K :call ShowManPageCursor() " Bind ShowManPageInput to Q map Q :call ShowManPageInput() " ============================================================= " To load a file in a new buffer - just a quick edit shortcut for commonly " edited files of mine. If the second argument is set to something, then " also scroll to the bottom of the file. If the third is set, recenter after " scrolling. function! LoadFile(filename, ...) " location of my quotes file. let filepath = expand(a:filename) " make sure it exists if ! filereadable(filepath) Error("ERROR: Can't find file") return endif " open the quotes file execute 'e ' filepath " do we need to scroll down and recenter? if a:0 > 0 execute 'normal G' if a:0 > 1 execute 'normal z.' endif endif " and we're done endfunction "Quotes " Set up commands to load some commonly-edited files. com! -nargs=0 Quotes :cal LoadFile("$HOME/projects/personal/mike/other/mike", 1, 1) com! -nargs=0 Functions :cal LoadFile("$HOME/.vim/functions.vim") com! -nargs=0 Vimrc :cal LoadFile("$HOME/.vimrc") com! -nargs=0 Gvimrc :cal LoadFile("$HOME/.gvimrc") com! -nargs=0 Exrc :cal LoadFile("$HOME/.exrc") com! -nargs=0 Vimnotes :cal LoadFile("$HOME/.vim/vimnotes") " to rid files of tabs and trailing whitespace com! -nargs=0 Clean :%s/ / /g | :%s/ *$//g " Function to package my vim config files. function! PackageConfigs() let home = expand("$HOME") let files = home . "/.exrc " . home . "/.vimrc " . home . "/.gvimrc " . home . "/.vim" let outputfile = home . "/vimconfig.tar" " Delete an existing tar.gz file. let tgzfile = outputfile . ".gz" if filereadable(tgzfile) cal delete(tgzfile) endif let command = "tar -cvf " . outputfile . " " . files echo "Tarring files..." cal system(command) " The output file had better exist. if ! filereadable(outputfile) Error("The output file does not exist - tar must have failed.") endif " now gzip the file let command = "gzip " . outputfile echo "Zipping files..." cal system(command) echo "Done." endfunction " a command to execute the above com! -nargs=0 PackageConfigs :cal PackageConfigs()