EDITOR environment variable changes after reboot

Solution 1:

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.

Solution 2:

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.

Solution 3:

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

export EDITOR=vi