How to change the default text editor in Debian.


There is a never-ending argument among Linux users over which text editor is the best when it comes to text editors. Well, after your choice is personal; I've seen folks sticking to a single editor while others use 3 to 4 at the same time. It all depends on the task and the features it offers. Fortunately, there are ways to change the default command-line text editor used by different programs, such as ansible, visudo, or crontab. Here we are going to tackle 2 methods.

🎧


Method #1

Using the update-alternatives --config editor you are given a list of the text editors available in your system with the default one marked with an asterisk (*).

The prompt expects a number matching the text editor you want to set.

$ sudo update-alternatives --config editor

Output

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

Press <enter> to keep the current choice[*], or type selection number:

Method #2


For instance, to use nano as the default text editor, you need to change the VISUAL and EDITORenvironment variables. If you are using ZSH, you can declare the variables in the ~/.zshrc (per-user shell-specific configuration files) by adding those lines to your ~/.zshrc file.

export VISUAL=nano
export EDITOR="$VISUAL"


Save and exit the file.
The change will only take effect after you restart the shell.

source ~/.zshrc

The above will load the new environment variables into your current shell session.




Well, that is the end of our post.
We hope you've found it informative.
See you next time!