Linux: how to change default editor

Sometimes Linux default editor (usually “you” or “vim”) is not the most comfortable, especially for users that often use other editors like “nano”.

There are several online tutorials on how to change the default editor, but those procedures are often wrong and we realize that when, for example, we try to edit crontab (with the command crontab -e) and the old editor still come up.

In this article we will see how to change Linux default editor globally, or only for a specific user.

Editor installation

The first thing to do of course is to install, if not already present, the new editor (eg. “nano”), with the following command:

yum install nano (for CentOs/Redhat-based Linux distributions)
apt-get install nano (for Debian/Ubuntu-based Linux distributions)

At this point you have two options:

1. Set the default editor for a single user profile

You will simply have to edit .bash_profile file of your profile (eg .: /root/.bash_profile or /home/nullalo/.bash_profile, or generally ~/.bash.profile for currently logged in profile) and add the following lines:

export VISUAL="nano"
export EDITOR="nano"

2. Set the default editor globally

In this case you will have to edit /etc/bashrc file and add (possibly at the end of it) the following lines:

export VISUAL="nano"
export EDITOR="nano"

Final check

To make sure everything is ok, you need to disconnect and reconnect your user and ensure that with the following command:

crontab -e

new editor is used (in our case “nano”) in place of the old one (eg.: “vi”).


Remember that the local editor, that is the one specified for a single profile, always overrides the global one: therefore, if you set “nano” in /etc/bashrc file and “vi” in the ~/.bash_profile file, your profile will use “vi” as editor, and not “nano”.

The difference between the environment variables VISUAL and EDITOR is that EDITOR should be able to operate without the use of “advanced” terminal capabilities, while VISUAL may be a full screen editor such as vi or emacs. If you call an editor via bash, it will first try to use the editor defined in VISUAL, and in case of failure (maybe because terminal does not support a full-screen editor) it will use the editor defined in the variable EDITOR. The advice is to set EDITOR to the value “vi -e”.

Previous post

Linux scripting: how to fix "bad interpreter" error

Next post

How to configure PhpStorm for Laravel

Fulvio Sicurezza

Fulvio Sicurezza

1 Comment

  1. shifu
    Friday August 9th, 2019 at 01:42 PM — Reply

    Thank you very much!

Leave a reply

Your email address will not be published. Required fields are marked *