[vox-tech] serendipity with vim
Peter Jay Salzman
vox-tech@lists.lugod.org
Fri, 2 Apr 2004 10:33:11 -0800
these are the macros i use most.
this is VERY useful when you're editing email. a truly wonderful macro
that reformats paragraphs to linewidth. i use it all the time. just
press the "home" key to reformat a paragraph.
" Formats a paragraph (using home key). Sets width textwidth.
map <kHome> gq}
map <Home> gq}
this next macro may be my favorite. rather than running a spell checker
on a whole email, checks a single word for spelling. much faster. or
if someone uses a word i don't know, just place the cursor over the word
and press delete. you have to apt-get dict, of course.
" This is my favorite mapping!
" <del> in insert/cmd mode runs dict on word which the cursor is on.
map <del> :!dict <cword><CR>
this one is neat. when i program on a console, i like to stick with 80
characters per line. when i'm using X, i sometimes relax that. when i
want to use 80 cols/line when i program in X, i override this with a
modeline:
" If I'm programming in an xterm, unset textwidth. If I'm in a console,
" use 80 columns per line, otherwise things get unreadable.
if $TERM == "xterm"
au BufNewFile,BufRead *.f90,*.for,*.c,*.cc,*.html,*.pl,*.tex set tw=0 wm=0
endif
i use the "q" recording facility all the time, but i also hit "q" often
enough to push it out of the way so i don't hit it by accident:
" Make Q start recording instead of q. I always hit q in cmd mode.
noremap q <Nop>
noremap Q q
and multi-session yanks are always cool:
" _Y: Yank the highlighted block of text (or a single line) to a tmp file.
" _P: Put the text yanked with \_Y (possibly in another invocation of Vim).
nmap _Y :.w! ~/.vim_yank_tmp<CR>
vmap _Y :w! ~/.vim_yank_tmp<CR>
nmap _P :r ~/.vim_yank_tmp<CR>
lastly, this is cool. say you're programming some C code and you forgot
how a function is prototyped. or perhaps you just added a function to a
.c file and you want to add a prototype quickly to the .h file. or say
you just started writing a .c file, and you want to create the .h file.
all you got to do is type "header" in colon mode:
cmap header sp %:r.h
pete
ps- i love seeing people's vim tips. it's cool seeing what people find
useful.
--
Make everything as simple as possible, but no simpler. -- Albert Einstein
GPG Instructions: http://www.dirac.org/linux/gpg
GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D