5

I am using Ubuntu 12.04. Not that I am complaining as I like my vim and prefer its many features. However, I’m curious as to why it does it. It is not aliased in .bashrc or .bash_profile. I am not sure where it gets this behaviour from. Could someone please explain? And also, out of curiosity, is it possible to fire up classic vi?

2
  • 2
    On many systems vi is a symlink to vim. (If it is a symlink you probably can not open classic vi)
    – FDinoff
    Dec 13, 2014 at 17:05
  • 1
    ... to check that: type ls -l /usr/bin/vi tis will give you ` /usr/bin/vi -> /etc/alternatives/vi` then type ls -l /etc/alternatives/vi you will get /etc/alternatives/vi -> /usr/bin/vim.basic Dec 13, 2014 at 18:25

3 Answers 3

8

Because Vim is a well-maintained, vi-compatible, Open Source editor, so it is a perfect match for Linux. I've last seen implementations of pure "vi" on proprietary Unixes like SunOS, HP-UX, AIX; you might get "lucky" on BSD, too. (But of course Vim can be installed on those, too.)

On Ubuntu, what gets installed by default is a stripped-down version of Vim (vim-tiny); enough to do vi-style editing. Real Vim users usually install the vim-gnome package for a full installation, including the graphical GVIM.

1
  • 1
    Note: Arch comes with the original vi by default.
    – romainl
    Dec 13, 2014 at 22:21
7

vim is the sucessor to vi. It stands for vi improved.

/usr/bin/vi is just a symlink to vim. You can see this with:

ls -l /usr/bin/vi

To start "classic vi":

vim -u NONE myText.txt

How it works: vim looks for a config file at ~/.vimrc, if this is found it will run as vim unless the line set compatible appears in .vimrc. To save editing the .vimrc and adding that line, we tell vim not to bother looking for .vimrc with the -u NONE option.

Instead of the NONE you could specify a different handwritten config file more suited to setting up vi (vim's .vimrc often confuses vi as it can contain modern vim-specific additions.)

As to why vi is a symlink to vim I've only heard people's opinons. Some say it was to enable running of old scripts. But I don't think I've seen vi or vim invoked in a script much. Others say it was for programmers hardwired to type vi when they want to edit.

2
  • 1
    vim checks argv[0]. If that is vi, it runs in compatibility mode. See also sendmail and mailq and similar programs where functionality of the program can be switched by calling it a different name.
    – user220438
    Dec 13, 2014 at 23:25
  • Running vim version 8.0 adding set compatiblity produces a error the next time vim is started. The option seems to be set compatible instead. Thus changed the answer.
    – MadMike
    Dec 4, 2017 at 13:49
4

Debian and Ubuntu use a system where symlinks are used to point to alternatives. This is managed using update-alternatives. (man 8 update-altnernatives)

You'll find /usr/bin/vi is symlinked to /etc/alternatives/vi and that is symlinked to something like /usr/bin/vim.gnome.

The following command will show you which binaries you have installed that provide vi functionality:

sudo update-alternatives --list vi

This will let you pick a vi binary interactively:

sudo update-alternatives --config vi

This will let you pick one manually, for example:

sudo update-alternatives --set vi /usr/bin/nvi

This will let you revert to automatic settings:

sudo update-alternatives --auto vi

Like others have said, vim can run in vi compatibility mode, but there's a pretty basic vi clone called nvi that you can install as well.

sudo apt-get install nvi

You must log in to answer this question.

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