Exit Wiki

A lot of Unix utilities need to open your text editor. On OS X this editor defaults to vi (or vim, in 10.3), which is a good, if slightly unfriendly, Unix editor.

But I don't want to learn how to use another editor! I already know how to use BBEdit, can't I use that?

You actually can, but it's non-obvious.

Step #1: Make a wrapper shell script

To be safe, you should make a shell script that wraps the bbedit command line tool. Open BBEdit (the application), and make a new file with the following contents:

#!/bin/sh
bbedit -w "$@"

the -w parameter tells the bbedit command line tool to wait around until you are finished editing the file.

Save that file somewhere (I have a bin folder in my home directory for things like this). Make sure you save it with no spaces in the filename.

Step #2: Make it executable

On the command line:

$ chmod u+x path/to/filemade

(u+x means the User can eXecute this file... it should be run as a program)

(where path/to/filemade is the path to the file... in BBEdit I saved my file as "bbeditwrap" in my bin directory of my home folder, so my path would be ~/bin/bbeditwrap)

Step #3: Set the EDITOR

On the command line again:

$ export EDITOR=path/to/filemade

Now the command line should open BBEdit, instead of vi, when it needs an editor.

Proving The Point

You can prove the point several ways.

$ echo $EDITOR

should be /path/to/filemade

$ crontab -e

Edit your crontab (cron schedules tasks to happen certain times of the day). This should open in BBEdit, since that is where EDITOR points to.

Persistence

You may want to always use BBEdit as your EDITOR. Great. What you need is a .profile file. We'll assume you don't have one already, and walk you through creating one. It never hurts to check to make sure, and ls -a ~/.profile will do it - if the command echos .profile back at you, you already have one.

In BBEdit, make a new document. Paste the export EDITOR line from Step #3 into this new file. Save the file as profile in your home folder.

Really the file should be named .profile, but you can't save the file as that in BBEdit. Nor can you rename it in the Finder itself. So, in Terminal, run the following command:

$ mv ~/profile ~/.profile

Now every time you open up a new Terminal window, your EDITOR should be set properly. It never hurts to check, of course, so feel free to go back and try some of the tests from the Proving The Point section on a new terminal window.

References

bbedit command line tool man page (man bbedit)

BBEDIT as main EDITOR (last edited 2006-10-13 16:10:08 by RyanWilcox)