Just some guy on the internet.


authors: [“Luke Rawlins”]
date: 2016-12-03
draft: false
title: Change the Default Text Editor in Ubuntu
description: “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.”
url: /change-editor-in-ubuntu/
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 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.