Subscribe to How-To Geek

Recommended: Click Here to Run a Free Scan for Common PC Errors   [Sponsored Link]

Change the Default Editor From Nano on Ubuntu Linux

Many of the utilities in Ubuntu Linux use a text editor to allow you to edit configuration options and files. An example of this is using the crontab command, which allows you to edit your cron jobs using the default editor.

It's really easy to set the default editor using the update-alternatives command. Open up a terminal window and type in the following command:

sudo update-alternatives –config editor

Here's an example of what you'll see:

$ sudo update-alternatives –config editor

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

You can select the editor you want by just typing in the number. For example, if I want to change the default editor to vim, I would just hit the number 1.

You can test this out by typing in crontab -e to edit your cron file. You should see the editor that you chose, instead of the default.

The Geek is the founder of How-To Geek and a geek enthusiast. When he's not coming up with great how-to articles, he's probably writing at his personal blog. This article was written on 12/5/06 and tagged with: Ubuntu, Ubuntu Tips & Tweaks

Comments (14)

  1. Warren

    Thanks, I'm only starting to use a Linux OS and was just starting to get to grips with VIM and then having to learn another text editor for Unbuntu would have been an inconvenience.

  2. djancak

    Thanks for this information. I was getting rather fed-up with having to use nano as my default text editor when using crontab.

  3. pd

    This doesn't seem to work.

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

  4. andres

    Little tricks make life easier, thanks budy, very helpful.

  5. andres

    this is the correct command

    "update-alternatives –config editor"

    with 2 dashes instead of one

  6. pd

    I found this tip failed. It did nothing after eventually I had to find out the double dash –config thing myself.

    It would also be much more sensible to put tips that rely on strict command line arguments, in a fixed width font to make them easier to read.

    Thumbs down for this tip.

  7. Gustaf

    Does this comment engine change two dashes into one long? Otherwise, _this_ is the correct command:

    "update-alternatives –config editor"

  8. Gustaf

    Followup:
    *Sigh* it certainly did.. Nevermind; sorry for the double posting.

  9. ronald

    maybe write is as 'update-alternatives - -config editor' :D

    greetz all

  10. Micah

    When I run update-alternaitives, it only shows ed and nano. Is there anything I can do to to get it to show the other choices?

    Thanks!

  11. Gustaf

    ronald:
    Hehe. No, seriously not. "-" is generally a syntax for stdin/stout, can cause trouble..

    Micah:
    A first dumb question then: Have you even installed vim or any other alternatives? I think a full installation of e.g. vim or emacs is not bundled by default.

  12. Micah

    oh yeah - I've been using VIM ever since install. In fact, I didn't know about this and set up VIM as the edior in my .bashrc.

    Thanks

  13. Bauche

    I have installed vim but it does not appears as an alternative. (It appears vim.basic and vim.tiny, but not vim). What con I do?

  14. Gustaf

    vim.basic = vim, so that's what to choose. Before the installation there was only vim.tiny available.


Leave a Comment




Leave your friendly comment here. If you have a computer help question, leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Copyright © 2006-2008 HowToGeek.com. All Rights Reserved.