Change the Default Text Editor in Ubuntu

By: Luke Rawlins Dec 3, 2016 | 2 minutes read
Share this:

Tags: Linux, Ubuntu, VIM

Change the Default Text Editor in Ubuntu

vim

So I’m a huge advocate of Ubuntu. It has long term support releases, more packages than you would ever need, free online unattended patching, and you always have an in-place upgrade path to the next LTS version. What more could you ask for? I’d like to ask that nano lose its privileged status as the default text editor!

When making changes to sudoers, passwd, or group files you should really be using the built-in tools visudo, vipw, and vigr. These tools will check your syntax prior to committing changes to the file that could break your system. By default, Ubuntu opens these files in nano which I find bothersome. If like me you would rather use vim when making these changes here’s how to change the default.
Change Ubuntu’s default editor with update-alternatives.

Option 1) change the editor interactively.

sudo update-alternatives --config editor

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:

You can see that the option we want is 3 vim.basic which after selecting will change the default from nano to vim.

Option 2) change the editor with a single command string.

Alternatively and probably better if you need to script it is to just set the default with a single command string.

sudo update-alternatives --set editor /usr/bin/vim.basic

This command will output a confirmation that the editor has been changed to vim.

You can verify that your change has been made as follows:

sudo update-alternatives --query editor

This command will output a lot of information:

Name: editor
Link: /usr/bin/editor
Slaves:
editor.1.gz /usr/share/man/man1/editor.1.gz
editor.fr.1.gz /usr/share/man/fr/man1/editor.1.gz
editor.it.1.gz /usr/share/man/it/man1/editor.1.gz
editor.ja.1.gz /usr/share/man/ja/man1/editor.1.gz
editor.pl.1.gz /usr/share/man/pl/man1/editor.1.gz
editor.ru.1.gz /usr/share/man/ru/man1/editor.1.gz
Status: manual
Best: /bin/nano
Value: /usr/bin/vim.basic
Alternative: /bin/ed
Priority: -100
Slaves:
editor.1.gz /usr/share/man/man1/ed.1.gz
Alternative: /bin/nano
Priority: 40
Slaves:
editor.1.gz /usr/share/man/man1/nano.1.gz
Alternative: /usr/bin/vim.basic
Priority: 30
Slaves:
editor.1.gz /usr/share/man/man1/vim.1.gz
editor.fr.1.gz /usr/share/man/fr/man1/vim.1.gz
editor.it.1.gz /usr/share/man/it/man1/vim.1.gz
editor.ja.1.gz /usr/share/man/ja/man1/vim.1.gz
editor.pl.1.gz /usr/share/man/pl/man1/vim.1.gz
editor.ru.1.gz /usr/share/man/ru/man1/vim.1.gz
Alternative: /usr/bin/vim.tiny
Priority: 10
Slaves:
editor.1.gz /usr/share/man/man1/vim.1.gz
editor.fr.1.gz /usr/share/man/fr/man1/vim.1.gz
editor.it.1.gz /usr/share/man/it/man1/vim.1.gz
editor.ja.1.gz /usr/share/man/ja/man1/vim.1.gz
editor.pl.1.gz /usr/share/man/pl/man1/vim.1.gz
editor.ru.1.gz /usr/share/man/ru/man1/vim.1.gz

Notice specifically the lines labeled:

Status: manual
Best: /bin/nano
Value: /usr/bin/vim.basic

This output confirms that we switched from automatic selection to manual selection of our editor and that instead of the “Best” (Say’s who!?) value we chose vim.

Related Posts


Free SSL Certificate with Let’s Encrypt

Free SSL Certificate with Let’s Encrypt If you have ever installed an SSL certificate you know that it can be a tedious process. Let’s Encrypt makes this easy. Just call the letsencrypt command from the terminal and point it at your domain. Securing your website with a valid ssl certificate from a recognized and trusted vendor shows your website visitors that information transmitted between your site and their browser is encrypted. Read more

Bruh, do you even live patch?

Patching is arguably the single most important thing you can do to keep your systems secure. It’s also tedious, boring work that ends with everyone’s least favorite activity…. rebooting some indispensable, far too important for downtime server. Often meaning that patching takes a back seat to convenience, but no more! Starting with Ubuntu 16.04, and continuing on to the latest LTS Ubuntu 18.04 you can now update the kernel on a live system without a reboot. Read more

Passwordless login with SSH Keygen

What is a rsa key? RSA keys are a public key encryption method that keeps a private key on the host computer, and a public key on other machines. The public key is generated by a mathematical algorithm that can only be de-crypted with the private key. As long as the private key is kept confidential use of the keys is secure.Why use rsa keys? rsa keys are secure The keys are secure because they can be encrypted on a users computer protecting the key from falling into the wrong hands, like a password printed on a sticky note and place on your desk. Read more


Contact

If you’d like to get in touch, contact with me via email - or follow on Twitter.

[email protected]