21

I want to launch vim instead of the default vi editor when I hit v in less.

Are there any settings I can modify to allow me to do this?

32

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.

  • 6
    This 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. – Arcege Feb 10 '11 at 12:08
  • 2
    @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"). – Jürgen A. Erhard Feb 10 '11 at 12:27
  • @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. – gabe. Feb 10 '11 at 12:39
  • I 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). – Mei Jun 4 '11 at 6:26
4

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.

  • 1
    This is a really nice solution for all Debian-based distributions. – MattBianco Sep 20 '18 at 12:43
  • 1
    Good point, it might not work in other distros. I will add that to my post. – maxorcist Sep 20 '18 at 12:48
-1

You can also make an alias
alias v='vim'
and save it in your /.bashrc

  • 5
    This won't work from within 'less'. – pboin Feb 10 '11 at 11:45
  • 1
    @pboin probably like me I totally missed the fact that this was 'in less' on first and several repeat readings. I clarified the question. – xenoterracide Feb 10 '11 at 22:54

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.