change default text editor in Ubuntu

The default editor for crontab on Ubunut is Nano. I don’t like it. I just like vi (or the vim version for linux).

According to the official notes about changing the default editor, I should use this command:

$ sudo update-alternatives –config editor

This gives a screen like this:

$ sudo update-alternatives –config editor
[sudo] password for johannes:
There are 4 choices for the alternative editor (providing /usr/bin/editor).

Selection Path Priority Status
————————————————————
0 /bin/nano 40 auto mode
1 /bin/ed -100 manual mode
2 /bin/nano 40 manual mode
* 3 /usr/bin/vim.basic 30 manual mode
4 /usr/bin/vim.tiny 10 manual mode

Press enter to keep the current choice[*], or type selection number:

Well as you can see I choose number 3. That didn’t help.

What did help was this command:

$sudo select-editor

Select an editor. To change later, run ‘select-editor’.
1. /bin/ed
2. /bin/nano <—- easiest
3. /usr/bin/vim.basic
4. /usr/bin/vim.tiny

Choose 1-4 [2]:

I choose 3 and voila

the command sudo crontab -e opens in vi.

actually this command created a file ‘.selected_editor’ containing:

# Generated by /usr/bin/select-editor
SELECTED_EDITOR=”/usr/bin/vim.basic”

There are many ways leading to Rome, and this is just another one.