Can less invoke vim instead of the default vi when I hit the 'v' key?

From man less,

v      Invokes  an  editor  to edit the current file being viewed.  The
       editor is taken from the environment variable VISUAL if defined,
       or  EDITOR if VISUAL is not defined, or defaults to "vi" if nei‐
       ther VISUAL nor EDITOR is defined.  See also the  discussion  of
       LESSEDIT under the section on PROMPTS below.

Simply set standard EDITOR environment variable according to your wishes, e.g. export EDITOR=vim in ~/.bashrc or something like that.


I found an answer here https://www.howtogeek.com/howto/ubuntu/change-the-default-editor-from-nano-on-ubuntu-linux/ that shows how to change the default editor without having to change any environment variables. This will only work in Debian based distros though.

In short, type the command below into your cli:

sudo update-alternatives --config editor

which will give you a menu with your different editor options, like so:

$ sudo update-alternatives –config editor

There are 5 alternatives which provide `editor’.
Selection Alternative
———————————————–
1 /usr/bin/vim
2 /bin/ed
*+ 3 /bin/nano
4 /usr/bin/vim.basic
5 /usr/bin/vim.tiny
Press enter to keep the default[*], or type selection number:

Just enter the number of the editor you wish to set to default.