If you spend any amount of time in a terminal you very likely end up needing to use a text editor. Text editors can be very powerful tools, and therein introduces the age-old editor wars. Vim vs Emacs, etc. No matter what your preferred editor is, it helps if it is the default. It is always a pain to be presented with an editor you’re not used to when trying to configure your system. This short article will outline how to change the default editor for your system, ensuring you’re always presented with your preference.
Linux provides a system tool called alternatives, which allows us to have multiple tools installed that each provide the same functionality. Using this tool we can tell the system which one we would like to use as the default, leaving the others available but not primary. To use the alternatives tool to change your default editor, use the command:
sudo update-alternatives –-config editor
You should be presented with a menu similar to this:
There are 4 alternatives which provide `editor'.
*+ 4 /usr/bin/vim.gnome
Press enter to keep the default[*], or type selection number:
Your options may vary depending on which editors you have installed. No matter what your options are, simply select the number you would like to use and your default editor is updated.
To test these new changes use a command that will call the default editor such as visudo or crontab -e.