When you edit configuration files using a command like sudo visudo or crontab -e, Ubuntu Linux will automatically open the file using its default command-line text editor. For most modern Ubuntu installations, this default is Nano. However, if you are a system administrator who prefers the power of Vim, or you accidentally set your default to an editor you don’t know how to exit, you can easily change the system-wide default using the update-alternatives tool.
How to Change the Default Editor
Ubuntu uses a system of symbolic links to manage default applications. You can reconfigure these links interactively.
- Open your terminal window or SSH into your server.
- Run the following command:
sudo update-alternatives --config editor - The terminal will output a list of all the text editors currently installed on your system (such as nano, vim.basic, vim.tiny, or ed).
The output will look something like this:
Selection Path Priority Status
------------------------------------------------------------
* 0 /bin/nano 40 auto mode
1 /bin/nano 40 manual mode
2 /usr/bin/vim.basic 30 manual mode
3 /usr/bin/vim.tiny 15 manual mode
The asterisk (*) indicates your current default editor.
Selecting Your Preference
At the bottom of the list, the prompt will ask: Press <enter> to keep the current choice[*], or type selection number:.
Simply type the number corresponding to your preferred editor (for example, type 2 for vim.basic) and press Enter.
The system will instantly update the symbolic links. From this point forward, any system command or script that relies on the generic $EDITOR variable will automatically launch your chosen application, saving you from having to manually specify your preference every time.