Score:3

How to set Vim as the default text editor in Linux (Ubuntu)?

io flag

I found another way to set Vim as the default text editor in Ubuntu but I would like to know why this tutorial is not working for me:

https://www.a2hosting.com/kb/developer-corner/linux/setting-the-default-text-editor-in-linux

Here's what I did:

I edited ~/.bashrc by adding these 2 lines:

export EDITOR='vi'
export VISUAL='vi'

Then I typed the command:

source .bashrc

I also tried to log out of my account and then log back in but it's still not working.

When I try to open the /etc/sudoers file it opens with Nano text editor instead of Vim.

us flag
`When I try to open the /etc/sudoers file` -- What command did you use to open that?
Chookitypok avatar
io flag
@Archisman Panigrahi `sudo visudo /etc/sudoers`
Score:9
ec flag

The following command changes the system's default editor:

sudo update-alternatives --config editor

You will get prompted with the available editors, select vim from the list.

Score:5
vn flag

The link that you followed was unfortunately generated by ChatGPT, and it demonstrates some of the issues with AI-generated content (and why we ban AI-generated answers here on Ask Ubuntu) see footnote. It's surprising, and a bit disappointing, to see a reputable hosting provider using ChatGPT-generated articles.

The reality is that there are, historically, many ways to choose an editor, and different applications use different methods. ChatGPT came up with a good "guess" (as it often does), but that method only works for some applications, so I'd consider it "wrong" as the answer to an article about, "How to set the default text editor in Linux". The correct answer would be something more like, "It depends on the application".

For instance:

  • crontab -e uses select-editor to allow the user to select their preferred editor the first time it is run. The EDITOR and VISUAL environment variables will override this selection, however, if either is present.

  • Conversely, git defaults to using vi, which can be overridden by the presence of an EDITOR or VISUAL environment variable, which can in turn also be overridden by the core.editor Git configuration.

  • visudo can use the EDITOR and VISUAL variables, but only (if I'm reading man visudo correctly) if the editor or env_editor settings are configured in sudoers. By default, in the absence of these settings and variables, it defaults to /usr/bin/editor. Under Ubuntu, with the alternatives system, /usr/bin/editor is a symlink to /etc/alternatives/editor, which in turn is a symlink to your preferred editor (nano by default).

    As mentioned in the other existing answer, this symlink (as with any in the alternatives system) can be updated using the update-alternatives command.

And these methods for choosing a default editor can even vary from distribution-to-distribution, and some defaults can be compiled into the applications.


Footnote

Certainly, it's easy for a human to make similar mistakes (and I can't promise that mine isn't error-free), but ChatGPT (currently, at least) seems to have a knack for delivering answers that don't quite answer the question that was asked (as in this case), or worse, completely make up settings that don't even exist.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.