By default, nano is the text editor in Ubuntu. Sometimes you may need to change the default text editor for applications like crontab, that require a text editor. For example, if you are comfortable with vi then you may want to set the default text editor to vi. There are two ways to do this. In this article, we will look at both these methods. Here are the steps to set default text editor in Ubuntu. You can also use them to change text editor in other Linux distributions like CentOS, Redhat, Debian, and other systems.
How To Set Default Text Editor in Ubuntu
You can change default text editor in Ubuntu by editing .bashrc file, or using update-alternatives command.
Open terminal and run the following command to open .bashrc file. Please use the dot(.) before its filename since it is a hidden file.
$ sudo vi ~/.bashrc
Add the following lines to .bashrc file to set default editor to vi in Ubuntu. Replace vi with the text editor of your choice.
export EDITOR='vi' export VISUAL='vi'
Save and exit the file.
Also read : How to Undo Git Add before commit
Now log out of your account and log in again, to apply changes. Alternatively, you can also run the following command.
$ sudo source .bashrc
That’s it. The default text editor in Ubuntu will be changed to vi.
Also read : How to Install AWS CLI in Ubuntu
Open terminal and run the following command. It will list all the editors available in your system, with a * displayed before the present default text editor.
$ sudo update-alternatives --config editor
When you enter the above command, you will see a prompt as shown below.
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:
In the above output, * is displayed before option 3 since it is our default editor. If you want to change the default text editor to vim, enter 1. If you want to continue with your existing default text editor, then enter 3.
Also read : How to Tar a File in Linux
That’s it. Your default text editor will be changed.
You can easily test the change by entering crontab -e command, which will open the default text editor.
$ crontab -e