My Profile Photo


I'm Jason, a web applications developer in the San Francisco Bay area.

Changing the Default Text Editor

Certain command line utilities drop into an external text editor program to accept certain types of input. For instance, when using the command ‘crontab -e’ to edit your cron table, your default text editor program will be opened up with the current cron table configuration. The same also applies to the Git versioning system when using the interactive rebase mode. This helps the program avoid supporting it’s own text editor, and allows the user to specify their preferred text editor.

To specify the default text editor, simply edit or place the following definition inside of the .bash_profile file in your home directory. This example uses ‘/usr/local/bin/mate -w’ to specify that the Textmate editor be used. You may configure this value to reflect the path for Vim, Nano, or any other text editor you wish to use.

export EDITOR="/usr/local/bin/mate -w"

It’s also possible to explicitly configure Git to use a specific text editor, thus overriding the default ‘EDITOR’ value specified in the command line environment. This is useful if you only want to change the behaviour of Git, and not affect the rest of your environment.

git config --global core.editor "mate -w"

UPDATE - 03/28/2013:

I recently switched to Sublime 2 text editor. After installing the application I created a symlink like so:

ln -s "/Applications/Sublime Text" /usr/local/bin/subl

After this was completed I added the following to my shell config file (.bash_rc / .zshrc):

# Text Editor
export EDITOR=/usr/local/bin/subl

If you plan on using Sublime with utilities that expect you to save and close the file before the utility continues, you’ll need to configure a subl_wait script as outlined here.

To use Sublime Text with Git during processes like an interactive rebase, configure it as the text editor using this command:

git config --global core.editor "subl -n -w"