Yet Another Way to Change the Default Text Editor in Ubuntu and Debian

Choosing the right text editor for your workflow can significantly improve productivity, especially when working with administrative tools like crontab or visudo, which rely on the system’s default editor. If you’re frequently using such tools, it’s essential to set your preferred editor so you don’t have to work with a less comfortable one like nano if you prefer vim, or vice versa.

For additional context, you can also explore related guides such as how to change the default editor in bash, zsh, and ksh, or even discover powerful find command tricks in this list of 20 find oneliners.

One of the easiest and most robust ways to change the default editor in Ubuntu and Debian is by using the update-alternatives system. This tool allows the administrator to configure the default applications for various services, including the system editor. Unlike setting environment variables per session or per user, this method ensures a system-wide configuration, consistent for all users unless overridden locally.

Using update-alternatives to Set the Default Editor

To begin, open a terminal and run the following command as root or with sudo:

sudo update-alternatives --config editor

This command brings up a menu listing all installed editors that provide the /usr/bin/editor alternative. Each entry is assigned a selection number, a path to the binary, a priority score, and its current status (automatic or manual mode).

For example, the output might look like this:

There are 5 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/emacs23     0        manual mode
  4            /usr/bin/vim.basic  30        manual mode
  5            /usr/bin/vim.tiny   10        manual mode

In this example, the asterisk (*) next to option 0 indicates the current selection (in auto mode). To switch to another editor, type the corresponding number of your preferred choice and press Enter. For instance, typing 4 will set vim.basic as the new default editor.

After making your selection, the changes will take effect immediately. The next time a command invokes the default editor—like crontab -e or visudo—it will launch the newly selected editor.

This method is especially helpful if you’re managing multiple systems or users, as it standardizes the behavior across environments without the need for user-specific environment variables. It also avoids the risk of misconfigurations in shell profiles.

For shell-specific setups or more advanced customization, check out this detailed guide on changing the default editor per shell.

Conclusion

Configuring the default text editor with update-alternatives provides a centralized, clean, and persistent way to ensure your preferred editor is always used in critical system tasks. It’s a safer and more robust approach than editing shell config files, particularly in shared or production systems.

Whether you’re a fan of vim, nano, emacs, or any other editor, making it your system default can greatly streamline your administrative workflow. Don’t forget to explore other related articles, such as how to reuse the last argument in Bash (Bash previous command argument) or how to master file permissions using find commands. A well-configured shell environment starts with the right editor.

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *