Change The Default Editor

By | 2009/09/09

If you spend any amount of time in a terminal you very likely end up needing to use a text editor. Text editors can be very powerful tools, and therein introduces the age-old editor wars. Vim vs Emacs, etc. No matter what your preferred editor is, it helps if it is the default. It is always a pain to be presented with an editor you’re not used to when trying to configure your system. This short article will outline how to change the default editor for your system, ensuring you’re always presented with your preference.

Alternatives

Linux provides a system tool called alternatives, which allows us to have multiple tools installed that each provide the same functionality. Using this tool we can tell the system which one we would like to use as the default, leaving the others available but not primary. To use the alternatives tool to change your default editor, use the command:

sudo update-alternatives –-config editor

You should be presented with a menu similar to this:


There are 4 alternatives which provide `editor'.
Selection    Alternative
-----------------------------------------------
1    /usr/bin/vim.tiny
2    /bin/ed
3    /bin/nano
*+        4    /usr/bin/vim.gnome
Press enter to keep the default[*], or type selection number:

Your options may vary depending on which editors you have installed. No matter what your options are, simply select the number you would like to use and your default editor is updated.

To test these new changes use a command that will call the default editor such as visudo or crontab -e.

2 thoughts on “Change The Default Editor

  1. SamD

    In the command shown above, the first character of '–editor' is a long dash and not a hyphen. Just do a copy and paste to the command line and you'll see what I mean. Please make the correction for your other readers.

    Other than that, nice tip.

    Reply
  2. Wesley

    $ sudo update-alternatives –-config editor
    update-alternatives: unknown argument `–-config'

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.