While I'm quite at home in vi, these days I tend to keep it as my lowest common denominator tool. I can be sure it will be on any *nix machine, so I remember enough to do basic editing. I'm sure I've forgotten more vi commands than I remember. But on my own Mac, there are times when years of unix habits die hard, and I could be editing the file in a GUI editor, but it was easier to fire up vi -- like when viewing with less and hitting v. So why not set $VISUAL to a GUI app like TextWrangler?
Because it's not quite that straight forward. Firstly, you need to use open -a TextWrangler, but that returns immediately, throwing you back into less. Then you also have to allow for the way that less (and others) call $VISUAL. So instead, I set $VISUAL to point to a script, ~/bin/tw, which contains the following:
#!/bin/sh
for FILE in "$@" ;
do
if [ -f "$FILE" ] ; then
open -a TextWrangler "$FILE" ;
fi
done
while (ps -auxc | grep -v grep | grep -q TextWrangler)
do
sleep 1 ;
done
Rather than mess with the $LESSEDIT variable, I just ignore files that don't exist, so that the line number passed by less is ignored (unless you like naming files something like "+16"). Now from less, when I hit v, TextWrangler opens with my file. As a bonus if I really want to get back to less, I can use Control-C to return to less with the editor still open.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20050208203457487