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
?
3 Answers
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
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.
-
1
vim
checks argv[0]. If that isvi
, it runs in compatibility mode. See alsosendmail
andmailq
and similar programs where functionality of the program can be switched by calling it a different name.– user220438Dec 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 beset compatible
instead. Thus changed the answer.– MadMikeDec 4, 2017 at 13:49
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
ls -l /usr/bin/vi
tis will give you ` /usr/bin/vi -> /etc/alternatives/vi` then typels -l /etc/alternatives/vi
you will get/etc/alternatives/vi -> /usr/bin/vim.basic