How to change the default text editor in Linux
All Linux distributions have a text editor set by default. For example, in Ubuntu,
nano is set as the default text editor for use in console mode. In Linux, you can change default editor to one of your choice by changing the
$EDITOR environment variable.
For example, to change the default editor from
vim, I need to open the
.bashrc file and append the following line.
#FILE: .bashrc ... export EDITOR="vim"
Various command line applications such as
visudo make use of the
$EDITOR variable to choose the default text editor.
How to change default text editor in Ubuntu
In Debian based Linux distributions (Ubuntu), you can change the default text editor using a script called
update-alternatives. This is how it is done …
Open a terminal and type the following command :
$ sudo update-alternatives --config editor
An alternative to using
sudo is to login as root, in which case, you can run the above command without using
sudo. Next you will be prompted for your password. After you enter the correct password, you are provided a list of console text editors found on your system. Pick your choice to change the default text editor.
[sudo] password for linuxandfriends: ***** There are 3 alternatives which provide `editor'. Selection Alternative ----------------------------------------------- 1 /usr/bin/vim.tiny 2 /bin/ed *+ 3 /bin/nano Press enter to keep the default[*], or type selection number: 1