Can less invoke vim instead of the default vi when I hit the 'v' key?
12,208
Solution 1
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.
Solution 2
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.
Related videos on Youtube
Author by
Zaid
Updated on September 17, 2022Comments
-
Zaid over 1 year
I want to launch
vim
instead of the defaultvi
editor when I hit v inless
.Are there any settings I can modify to allow me to do this?
-
Admin over 13 yearsThis won't work from within 'less'.
-
Arcege over 13 yearsThis may not matter to much anymore, but the original intent of the two environment variables was that VISUAL was curses-based (vi or emacs) and EDITOR was tty based (ed), which is why less looks for VISUAL first. There may still be programs out there that see this difference. I would suggest setting VISUAL instead of EDITOR.
-
Jürgen A. Erhard over 13 years@Arcege: small correction: VISUAL is supposed to point to a full-screen (and not line-based) editor. Even though vi was, deep down, a line-based editor ("vi" (originally) stood for "visual interface" (to "ex", an enhanced "ed").
-
gabe. over 13 years@Arcege: Definitely, I remember having some issues when I set EDITOR to vim. VISUAL is more suitable. I don't remember what the issues were, but if you use the cli frequently, you will likely run into them.
-
Admin over 13 years@pboin probably like me I totally missed the fact that this was 'in less' on first and several repeat readings. I clarified the question.
-
Mei almost 13 yearsI routinely set both VISUAL and EDITOR to vim or to vi. If you set them to vi, then ksh will automatically use vi key-bindings for history manipulation. You can link vi to vim (in fact, I thought most installs did this).
-
MattBianco over 5 yearsThis is a really nice solution for all Debian-based distributions.
-
maxorcist over 5 yearsGood point, it might not work in other distros. I will add that to my post.