How to Change the Default Text Editor in Ubuntu Linux

When you edit configuration files using a command like sudo visudo or crontab -e, Ubuntu Linux will automatically open the file using its default command-line text editor. For most modern Ubuntu installations, this default is Nano. However, if you are a system administrator who prefers the power of Vim, or you accidentally set your default to an editor you don’t know how to exit, you can easily change the system-wide default using the update-alternatives tool.

How to Change the Default Editor

Ubuntu uses a system of symbolic links to manage default applications. You can reconfigure these links interactively.

  1. Open your terminal window or SSH into your server.
  2. Run the following command:
    sudo update-alternatives --config editor
  3. The terminal will output a list of all the text editors currently installed on your system (such as nano, vim.basic, vim.tiny, or ed).

The output will look something like this:

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /bin/nano            40        auto mode
  1            /bin/nano            40        manual mode
  2            /usr/bin/vim.basic   30        manual mode
  3            /usr/bin/vim.tiny    15        manual mode

The asterisk (*) indicates your current default editor.

Selecting Your Preference

At the bottom of the list, the prompt will ask: Press <enter> to keep the current choice[*], or type selection number:.

Simply type the number corresponding to your preferred editor (for example, type 2 for vim.basic) and press Enter.

The system will instantly update the symbolic links. From this point forward, any system command or script that relies on the generic $EDITOR variable will automatically launch your chosen application, saving you from having to manually specify your preference every time.

Leave a Reply

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

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.

Receive our best articles and tips delivered straight to your inbox.