Home / Changing the default text editor on Linux

Changing the default text editor on Linux

The default command line text editor on Linux (and BSD varaiants) determines what is used when you run commands such as "crontab -e" and is often not what you want to use yourself. Typcially vi/vim is the default text editor; many people prefer emacs or other editors, and I prefer to use nano myself.

It’s easy to change this default text editor by using the system’s environment variables. Both the EDITOR and VISUAL environment variables determine which text editor is used at the default, and you can set either to change the default behaviour to the text editor you prefer like so from the command line:

export EDITOR=nano

The above example will make "nano" the default editor, and you can substitute "nano" for your preferred editor. You don’t have to specify the full path to the application, as long as it is located in one of the paths specified by the PATH variable, but it’s probably a good idea to, eg:

export EDITOR=/usr/bin/nano

You can find the full path to a file using the "whereis" command like so:

$ whereis nano
nano: /usr/bin/nano /usr/share/nano /usr/share/man/man1/nano.1.gz

Setting the EDITOR environment variable from the command line as shown above will only last as long as your current session; once you log out the default behaviour will apply again when you next log in. To make the change permanent, add the export value to your ~/.bash_profile file.

Adding the entry to your ~/.bash_profile file won’t take affect until it is re-read, which will happen when you log in again. You can re-read the file immediately by doing this:

. ~/.bash_profile

To make the default editor change global and apply to all users, unless overridden in their ~/.bash_profile file, you add the entry to the /etc/profile file.