Set the EDITOR environment variable in ZSH

When you start to use the command line more often you notice that quite some shell programs launch a text editor like nano or vim for you to edit a file or something in that regard. Most often these shell programs check for the shell environment variable EDITOR to see your preferred text editor for these type of tasks.

To see to what value EDITOR is set you just echo it out. Mind the $ sign before EDITOR when you reference a variable in the shell.

$ echo $EDITOR
vim

You can set the EDITOR variable per command like this:

$ EDITOR=nano git commit

What is unfortunate about setting it per command is that it doesn’t persist. In order to make this setting permanent you can set the default editor in the ~/.zshrc config file. This config file is specific for the ZSH shell so if you were to use bash for example you need to configure it somewhere else.

To make the EDITOR setting permanent you need to export it in your ~/.zshrc config file.

# ~/.zshrc

export EDITOR=nano

Afterwards the setting doesn’t take immediate effect. You can either close and reopen your terminal or source ~/.zshrc:

$ source ~/.zshrc

See Also

6 Non-Programming Books for Programmers