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?
I usually configure this behaviour globally using
update-alternatives
:I've already selected Vim, but
nano
is the Ubuntu default. You would type3
to select Vim in my example, if it weren't already selected.As well as
less
, any program that calls an editor (such assudoedit
) should now call the selected one.To make it permanent simply do the following in terminal:
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 theEDITOR
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.
You will need to add it to your
.bashrc
file, open it withnano
orvi
and add the following line: