Why does the 'vi' command open 'vim' editor?
Solution 1
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.
Solution 2
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.
Solution 3
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
Related videos on Youtube
G.Rassovsky
Updated on September 18, 2022Comments
-
G.Rassovsky over 1 year
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 classicvi
?-
αғsнιη over 9 years... to check that: type
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
-
-
romainl over 9 yearsNote: Arch comes with the original vi by default.
-
MadMike over 6 yearsRunning 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.