0

I've never worried about vimdiff on my own computer, where I have archlinux installed, so everything is up-to-date, generally speaking; I generally just used it, and I'm fine with it. After all, :version gives the same output whether I launch vi, or vim, or vimdiff.

On my work computer (Debian 10), however, vimdiff opens an older version of Vim than vi or vim.

I guess this has to do possibly with how I installed Vim and/or with /etc/alternatives or something. It's been a long time I played around with such stuff though (without truly understanding it, likely), so I don't remember much.


Feedback on the answer and comment(s)

ls -lF /etc/alternatives/ | grep bin/vim | sed 's/.*-> //' | sort -u

rsults in just in one result, namely /usr/bin/vim.gtk*. How is it possible, then, that vimdiff and vim open different versions? Or have I misunderstood the answer?

The output of type -a vimdiff is

vimdiff is /usr/bin/vimdiff
vimdiff is /bin/vimdiff

output of: type -a vim

vim is aliased to `/home/me/vim-dist/bin/vim'
vim is /usr/bin/vim
vim is /bin/vim

output of type -a vi:

vi is aliased to `/home/me/vim-dist/bin/vim'
vi is /usr/bin/vi
vi is /bin/vi

Both /bin/vim --version | head -n 1 and /usr/bin/vim --version | head -n 1 have the same output:

VIM - Vi IMproved 8.1 (2018 May 18, compiled Jun 15 2019 16:41:15)

and that's the version that runs when I execute vimdiff, older than the one that runs when I execute vim/vi.

15
  • 1
    Add the output of type -a vimdiff, and follow where that path leads
    – muru
    Mar 18, 2022 at 14:22
  • @muru, added to the question.
    – Enlico
    Mar 18, 2022 at 14:31
  • 1
    Debian's vim packages don't install install into /bin, they install into /usr/bin. Have you installed a non-packaged version of vim / vimdiff into /bin? Did you delete the /etc/alternatives/vimdiff symlink? Please add the output of /bin/vim --version | head -n 1 and /usr/bin/vim --version | head -n 1 to your question.
    – cas
    Mar 18, 2022 at 15:16
  • Yes, I have installed a non packaged version of Vim. I downloaded the repo and installed from it, but I didn't worry about vimdiff, thinking it would be isntalled together with vim. Apparently that's not the case?
    – Enlico
    Mar 18, 2022 at 15:23
  • OK. Is /usr/bin/vimdiff a symlink to /bin/vimdiff? are there any other vim binaries in /bin, or is it just vimdiff? is /bin/vimdiff a standalone binary or a hard- or symbolic link to another binary (maybe vim)?
    – cas
    Mar 18, 2022 at 15:24

2 Answers 2

1

You've aliased vi and vim to the one in /home/me/vim-dist/bin; presumably you'd also be fine just aliasing vimdiff as well.

For vimdiff to work properly it needs to be executed as "vimdiff" not as "vim" so you can't just alias "vimdiff" to /home/me/vim-dist/bin/vim as well.

However, there might already be a symbolic link in /home/me/vim-dist/bin named vimdiff. If there is then alias "vimdiff" to that.

If not it would probably work to create it.

cd /home/me/vim-dist/bin
ln -s vim vimdiff

Then alias "vimdiff" to /home/me/vim-dist/bin/vimdiff.

If you don't want to or can't create the links, it would probably work to alias "vimdiff" to /home/me/vim-dist/bin/vim -d.

alias vimdiff="/home/me/vim-dist/bin/vim -d"

(In your .bashrc or .zshrc or wherever you keep your aliases.)

An alternative to all the aliases would be to add /home/me/vim-dist/bin to your $PATH and make sure it appears prior to /bin and /usr/bin. See this if you're not familiar with changing your $PATH.

0

Huh? vimdiff is just a symlink to vim. On debian specifically, /usr/bin/vimdiff is a symlink to /etc/alternatives/vimdiff which is, in turn, a symlink to your preferred version of vim.

e.g. on my main desktop machine, with vim.gtk3 as my preferred vim:

$ ls -lF /usr/bin/vimdiff
lrwxrwxrwx 1 root root 25 May 18  2018 /usr/bin/vimdiff -> /etc/alternatives/vimdiff*

$ ls -lF /etc/alternatives/vimdiff
lrwxrwxrwx 1 root root 17 Nov  8  2019 /etc/alternatives/vimdiff -> /usr/bin/vim.gtk3*

You can see the available alternatives with:

$ update-alternatives --list vimdiff
/usr/bin/vim.basic
/usr/bin/vim.gtk3

and change it with:

$ sudo update-alternatives --config vimdiff
There are 2 choices for the alternative vimdiff (providing /usr/bin/vimdiff).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/vim.gtk3    50        auto mode
  1            /usr/bin/vim.basic   30        manual mode
  2            /usr/bin/vim.gtk3    50        manual mode

Press <enter> to keep the current choice[*], or type selection number: 

If I had more vim packages installed (like vim-tiny), then they would appear as options too.

It's possible to have different alternatives selected for vim and vimdiff (and several other *vim* programs - see below for some of the binaries). I suspect that's what you've done. If you want them to be the same, then use update-alternatives to change one or both of them.

$ ls -lF /etc/alternatives/ | grep bin/vim
lrwxrwxrwx 1 root root  17 Nov  8  2019 editor -> /usr/bin/vim.gtk3*
lrwxrwxrwx 1 root root  17 Nov  8  2019 eview -> /usr/bin/vim.gtk3*
lrwxrwxrwx 1 root root  17 Nov  8  2019 evim -> /usr/bin/vim.gtk3*
lrwxrwxrwx 1 root root  17 Nov  8  2019 gview -> /usr/bin/vim.gtk3*
lrwxrwxrwx 1 root root  17 Dec 24  2019 gvim -> /usr/bin/vim.gtk3*
lrwxrwxrwx 1 root root  17 Nov  8  2019 gvimdiff -> /usr/bin/vim.gtk3*
lrwxrwxrwx 1 root root  17 Nov  8  2019 rgview -> /usr/bin/vim.gtk3*
lrwxrwxrwx 1 root root  17 Nov  8  2019 rgvim -> /usr/bin/vim.gtk3*
lrwxrwxrwx 1 root root  17 Nov  8  2019 rview -> /usr/bin/vim.gtk3*
lrwxrwxrwx 1 root root  17 Nov  8  2019 rvim -> /usr/bin/vim.gtk3*
lrwxrwxrwx 1 root root  17 Nov  8  2019 vi -> /usr/bin/vim.gtk3*
lrwxrwxrwx 1 root root  17 Nov  8  2019 view -> /usr/bin/vim.gtk3*
lrwxrwxrwx 1 root root  17 Nov  8  2019 vim -> /usr/bin/vim.gtk3*
lrwxrwxrwx 1 root root  17 Mar 18 21:58 vimdiff -> /usr/bin/vim.gtk3*

(alternatively, you could run something like grep -r bin/vim /var/lib/dpkg/alternatives/)

Each of those can independently be set to point to a different alternative version of vim. I probably should install vim-tiny (or at least set most of the above to vim.basic), I don't really need fancy GUI or perl/python/ruby/tcl support built in to my vi. The only time I even use gvim is on the rare occasions when I run it from a GUI app or a file-browser.

1
  • Hi cas, I've update the question with some feedback. Would you mind giving a look at it?
    – Enlico
    Mar 18, 2022 at 12:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .