9

While running the less command, pressing v opens the file inside the editor. I have set the EDITOR environment variable to vi by running the command export EDITOR=vi.

It works perfectly fine as expected. However when I reboot the computer, the editor is no longer Vi. How do I make it permanent?

  • 1
    Please set that in your /home/$USER/.bashrc file – George Udosen Dec 4 '17 at 9:10
14

I usually configure this behaviour globally using update-alternatives:

$ sudo update-alternatives --config editor
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:

I've already selected Vim, but nano is the Ubuntu default. You would type 3 to select Vim in my example, if it weren't already selected.

As well as less, any program that calls an editor (such as sudoedit) should now call the selected one.

| improve this answer | |
  • +1; didn't think about that option as I answered here too :) – Videonauth Dec 4 '17 at 9:32
  • It's an amazing option but gets lost in all the traffic :-) – George Udosen Dec 4 '17 at 10:18
  • 3
    Thanks. This is very helpful. I also did "man update-alternatives" to resolve the curiosity. – Smile Dec 4 '17 at 10:26
8

To make it permanent simply do the following in terminal:

echo "export EDITOR=vi" >> ~/.bashrc

This will add the line to your .bashrc file which gets called every time you open a terminal window.

To answer why this will work even if there has been a similar line before added to .bashrc is simple. .bashrc is a script with will be read and executed in a linear way, and this method is adding this line as the last below all others, so it gets executed/evaluated as last. So if there has been a line before the value of the EDITOR variable will be overwritten by the line you add.

Alternatively, if you not want to create a mess you can as well using your favorite editor (vi, vim, nano, joe etc..) to do this change and add a line if none is present and if one is present edit it.

| improve this answer | |
4

You will need to add it to your .bashrc file, open it with nano or vi and add the following line:

export EDITOR=vi
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.