9

When you type vi in the terminal, the following output is shown

~                             VIM - Vi IMproved                                
~                                                                             
~                               version 7.3.547                                 
~                           by Bram Moolenaar et al.                            
~           Modified by [email protected]             
~                 Vim is open source and freely distributable                   
~                                                                               
~                        Help poor children in Uganda!                                                                             

So according to this, vi must be launching VIm.
But when you type vim it gives

aditya@aditya-desktop:~$ vim
The program 'vim' can be found in the following packages:
 * vim
 * vim-gnome
 * vim-tiny
 * vim-athena
 * vim-gtk
 * vim-nox
Try: sudo apt-get install <selected package>

This shows that vim is not installed.
Notably man vi and man vim launch the same man pages.

So what does the vi command actually launch?

3 Answers 3

18

It is vim-tiny: "Vi IMproved - enhanced vi editor - compact version".

I did this on 13.10:

user@ubuntu:~$ which vi
/usr/bin/vi
user@ubuntu:~$ which vim
user@ubuntu:~$ ls -l /usr/bin/vi
lrwxrwxrwx 1 root root 20 ago 13  2013 /usr/bin/vi -> /etc/alternatives/vi
user@ubuntu:~$ ls -l /etc/alternatives/vi
lrwxrwxrwx 1 root root 17 dic 20 04:39 /etc/alternatives/vi -> /usr/bin/vim.tiny
user@ubuntu:~$ apt-cache search vim.tiny
vim-common - Vi IMproved - Common files
vim-tiny - Vi IMproved - enhanced vi editor - compact version
user@ubuntu:~$ dpkg --get-selections | grep vim
vim-common                  install
vim-tiny                    install

As you can see, vim is not installed (empty output), vi is a symlink to /etc/alternatives/vi (see alternatives mechanism), which is a symlink to /usr/bin/vim.tiny, which belongs to package vim-tiny.

3
  • A shorter way to find this would be dpkg -S $(which vi)
    – psusi
    Mar 15, 2014 at 23:17
  • @psusi dpkg-query no path found. Mar 16, 2014 at 3:46
  • 3
    dpkg -S won't work for symlinks. Mar 16, 2014 at 4:20
8

If you do type vi:

➜  ~  type vi
vi is /usr/bin/vi

You will know where's the binary, now if you do:

➜  ~  ls -l /usr/bin/vi 
lrwxrwxrwx. 1 root root 20 jun 22  2013 /usr/bin/vi -> /etc/alternatives/vi

It's provided by the alternative vi, which can be known by:

➜  ~  update-alternatives --display vi
vi - auto mode
  link currently points to /usr/bin/vim.basic
/usr/bin/vim.basic - priority 30
  slave vi.1.gz: /usr/share/man/man1/vim.1.gz
  slave vi.fr.1.gz: /usr/share/man/fr/man1/vim.1.gz
  slave vi.it.1.gz: /usr/share/man/it/man1/vim.1.gz
  slave vi.ja.1.gz: /usr/share/man/ja/man1/vim.1.gz
  slave vi.pl.1.gz: /usr/share/man/pl/man1/vim.1.gz
  slave vi.ru.1.gz: /usr/share/man/ru/man1/vim.1.gz
Current 'best' version is '/usr/bin/vim.basic'.

So, in my case, vi is a symbolic link to the alternative vi which is provided by vim.basic.

You can change which package provided vi if you do sudo update-alternatives --config vi

2

It's similar to @ignis answer, but i reduced the steps.It only works, if the file is a symbolic link to another.You can get the original file path easily, if it has thousands of symlinks in it's path.

symlnk-->symlnk-->symlnk-->symlnk-->symlnk-->symlnk-->symlnk-->symlnk-->symlnk-->symlnk-->symlnk-->symlnk-->symlnk-->symlnk-->symlnk-->symlnk-->symlnk-->.................-->original file

$ which vi
/usr/bin/vi
$ ls -l $(which vi)
lrwxrwxrwx 1 root root 20 Feb 22 20:14 /usr/bin/vi -> /etc/alternatives/vi  # So /usr/bin/vi is an symlink to /etc/alternatives/vi
$ dpkg -S $(readlink -f $(which vi))    
vim-tiny: /usr/bin/vim.tiny

So vi belongs to the package vim-tiny.

readlink -f gives you the canonical path of the file(Original file path).

You must log in to answer this question.

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