" Ben Crowder's .vimrc " Last updated: 10-29-04 " http://www.blankslate.net/ set autoindent set autowrite set bs=2 " Allow backspacing over everything in insert mode set cino=>1s,e1 set history=100 " Remember 100 lines in /the history set incsearch " Show the match as you type it in set joinspaces set keywordprg=aspell set laststatus=2 " Always show a status line set magic "set mouse=a set nobackup " Don't save backup files set nocin set nocompatible " Use Vim defaults set noexpandtab " Never put spaces in for tabs set noignorecase set nohlsearch " Don't highlight search results set nostartofline "set ruler " Redundant with the statusline set sbr=+ " Character to show wrapped lines set scrolloff=3 " Give two lines of lookahead when scrolling set shiftwidth=4 set showcmd " Show commands as I type them set softtabstop=4 set tabstop=4 " I prefer four spaces for tabs set textwidth=79 " Wrap lines at 79 characters set undolevels=1000 " Save my skin :) set viminfo='20,\"50 " Read/write a .viminfo file, don't store more " than 50 lines of registers set whichwrap=h,l,~,[,],<,> " Wrap horizontally with h/l and arrow keys set wrap " Long lines wrap " Use ',' for the mapping character () let mapleader="," au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif " Wrap mail messages at 68 characters (when I'm editing in mutt) autocmd filetype mail setlocal textwidth=68 " For Project Gutenberg etexts I'm working on au BufNewFile,BufRead *.gut set textwidth=65 au BufNewFile,BufRead *.gut set expandtab au BufNewFile,BufRead *.gut set scrolloff=4 " For an Old Icelandic primer I'm working on au BufNewFile,BufRead *.ice set textwidth=65 au BufNewFile,BufRead *.ice set encoding=utf-8 au BufNewFile,BufRead *.ice set ff=unix au BufNewFile,BufRead *.ice set expandtab au BufNewFile,BufRead *.ice set nocin au BufNewFile,BufRead *.ice set scrolloff=4 au BufNewFile,BufRead oiprimer.* set encoding=utf-8 au BufNewFile,BufRead *primer.tex set encoding=utf-8 " RELAX NG schema au BufNewFile,BufRead *.rng set filetype=xml " Try to get Home and End working map [1~ ^ map [1~ 0 map [1~ map [4~ $ map [4~ " A shorter way to reformat a paragraph map gqq gqap " Turn on syntax highlighting if the terminal has colors if &t_Co > 2 || has("gui_running") syntax on endif " Abbreviations ab _www http://www.blankslate.net/ ab _email crowderb@byu.edu ab teh the ab hte the ab htem them ab hten then ab taht that ab htat that ab ahve have ab adn and ab nad and ab goign going ab thign thing ab waht what ab hwo who ab hwat what ab wnat want ab hwere where ab iwth with ab almsot almost ab unkown unknown ab ot to ab lfpg Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch " Cycle through open buffers noremap :bnext inoremap :bnext " Cycle through open windows noremap w inoremap w " Close the current buffer map :bdelete " My color scheme highlight Visual ctermfg=Blue ctermbg=White highlight StatusLine ctermbg=Blue ctermfg=White cterm=bold highlight StatusLineNC ctermfg=Blue ctermbg=White " Run LaTeX on the current file map ,rl :!latex % " Create a PostScript file from the DVI of the current file (use ,rl first) map ,cps :!dvips %<.dvi -o:!gv %<.ps " For copying and pasting between different Vim sessions nmap _Y :.w! ~/.vi_tmp vmap _Y :w! ~/.vi_tmp nmap _P :r ~/.vi_tmp " Move to the next/previous buffer noremap :bn noremap :bp " Toggle paste mode nnoremap \tp :set invpaste paste? nmap \tp imap \tp set pastetoggle= " Show tabs and trailing whitespace nnoremap \tl :set invlist list? nmap \tl imap \tl set listchars=tab:»·,trail:·,eol:$ " This will let me have Vim autowrap quoted text set comments=nb:> " Gives me a menu of options when I hit Tab to complete set wildmenu " Date and time stamps for logs function! InsertTime() execute "normal I\" . strftime("%l:%M%P") . "\bbbhd1lwwwd1la. " endfunction imap ,d :r !date +"\%-m-\%-e-\%y: [\%A]"o imap ,t :call InsertTime() " For when I accidentally hold down Shift too long command! Q quit command! W write command! Wq wq " Don't skip past wrapped lines nnoremap j gj nnoremap k gk vnoremap j gj vnoremap k gk nnoremap gj nnoremap gk vnoremap gj vnoremap gk inoremap gj inoremap gk " This will move the working directory to the directory the current file is in " autocmd BufEnter * :cd %:p:h " Search and fold to show results function! Foldsearch(search) normal zE "erase all folds to begin with normal G$ "move to the end of the file let folded = 0 "flag to set when a fold is found let flags = "w" "allow wrapping in the search let line1 = 0 "set marker for beginning of fold while search(a:search, flags) > 0 let line2 = line(".") "echo "pattern found at line # " line2 if (line2 -1 > line1) "echo line1 . ":" . (line2-1) "echo "A fold goes here." execute ":" . line1 . "," . (line2-1) . "fold" let folded = 1 "at least one fold has been found endif let line1 = line2 "update marker let flags = "W" "turn off wrapping endwhile " Now create the last fold which goes to the end of the file. normal $G let line2 = line(".") "echo "end of file found at line # " line2 if (line2 > line1 && folded == 1) "echo line1 . ":" . line2 "echo "A fold goes here." execute ":". line1 . "," . line2 . "fold" endif endfunction " Command is executed as ':Fs pattern'" command! -nargs=+ -complete=command Fs call Foldsearch() " Show syntax highlighting group for the word the cursor is on map :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" " Toggle the current fold function! ToggleFold() if foldlevel('.') == 0 normal! l else if foldclosed('.') < 0 . foldclose else . foldopen endif endif " Clear status line echo endfunction " Map this function to Space key. noremap :call ToggleFold() " Make the current window as big as possible function! ToggleMaxWins () if exists ('g:windowMax') au! maxCurrWin exe "normal \=" unlet g:windowMax else augroup maxCurrWin " au BufEnter * exe "normal \_\\" " " only max it vertically au! BufEnter * exe "normal \_" augroup END do maxCurrWin BufEnter let g:windowMax=1 endif endfunction map max :call ToggleMaxWins () " My preferred statusline set statusline=[%02n]\ %F%(\ %r%y%m%)\ %=%c%V,\ %l/%L\ \ %P imap ggVG nmap ggVG