vim (not vi) runs in compatible mode by default

Bug #667235 reported by anatoly techtonik
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
vim (Ubuntu)
New
Undecided
Unassigned

Bug Description

Binary package hint: vim

Please read this report from the user's point of view, because as a developer you probably already have tuned `vim` to run in nocompatible mode.

When you install `vim` in Ubuntu, it may run in "compatible mode". "compatible mode" causes arrow keys to output A, B, C, D in insert mode, remove --INSERT-- marker from the bottom line, 'u' to undo only the last change, 'cw' not erasing the word before editing, etc. When `vim` is switched into compatible mode - it causes a lot of frustration.

"compatible mode" is needed, because `vim` replaced `vi` editor many years ago and people used to the behavior of old editor. These people still used `vi` command to invoke the editor, but this time it was new `vim` working behind the scenes. People could set "nocompatible" option in config file to use the latest and greatest features of 'vim' while still invoking it with `vi` command.

It is logical to assume that to avoid extra configuration people could execute `vim` command to run `vim` in nocompatible mode and `vi` to work in compatible. But many Ubuntu releases have passed, installed and removed, and this is not achieved yet. I hope we all agree that by executing `vim` we want the default features of `vim` and not `vi` in Ubuntu. Let's see that this doesn't work consistently.

First, remove your current `vim`:
$ sudo rm -rf /etc/vim
$ rm ~/.viminfo
$ rm ~/.vimrc
$ sudo aptitude purge vim vim-common vim-gnome vim-gui-common vim-runtime vim-tiny

Now install `vim-tiny` as it is the version of `vim` that comes preinstalled in Ubuntu through ubuntu-minimal core package (see http://packages.ubuntu.com/source/maverick/ubuntu-meta for the full list of packages installed in Ubuntu by default):
$ sudo aptitude install vim-tiny
$ vim
bash: /usr/bin/vim: No such file or directory

There is no `vim`, but if you launch `vi` you will actually see `vim` title screen. Of course, being executed as `vi` it runs in compatible mode by default. Now installing `vim`:
$ sudo aptitude install vim
$ vim

It runs in `nocompatible` mode and seems like everything works as expected. What about `vi`:
$ vi
:set compatible?
nocompatible

This is bug#1 - installed `vim` package changes default behavior of `vi` command, i.e. implicitly changes behavior of other package. When users used to the fact that `vi` command has arrow keys and syntax highlighting support, they forget that it is was actually provided by `vim` and start to experience problems on new systems. About 80% of `vim` questions here are about "vim features that don't work in vi" - https://answers.launchpad.net/ubuntu/+source/vim That's definitely a Frequently Asked Question.

Let's try to return `vi` the original behavior, so that `vi` runs in compatible mode and `vim` is not. It is safe to assume that mode problems are caused by configuration files. Let's get rid of them:
$ sudo rm -rf /etc/vim
$ vi
:set compatible?
  compatible

Good. What about `vim`?
$ vim
:set compatible?
  compatible

This is bug #2: vim (not vi) runs in compatible mode by default.

Let's try to fix this by reinstalling vim:
$ sudo aptitude remove vim
$ sudo aptitude install vim
$ vim
:set compatible?
  compatible

As you can see it is not fixed. All these bugs could be avoided if `vi` command provided in Ubuntu as a script that launches `vim` in forced "compatible mode" while the `vim` command itself without any configuration always work in "nocompatible".

description: updated
description: updated
description: updated
description: updated
description: updated
Revision history for this message
anatoly techtonik (techtonik) wrote :

I've edited bugreport, because in the process of reporting it new facts where discovered that slightly changed the meaning. Please reread it, if you opened the report before the timestamp in this comment.

description: updated
Revision history for this message
James McCoy (jamessan) wrote :

Your stated bug #1 is not a bug. The vi name is managed by the alternatives system. Packages with more functionality have a higher priority in the alternatives system. As such, installing the vim package installs a higher priority alternative for the vi name. If you want to use the vi binary from the vim-tiny package, then you can configure that by using the update-alternatives command.

The sole reason that vim-tiny's vi binary runs in compatible mode is because the binary is providing the expected vi that should be part of any base install of a unix system. This is the same reason that vim-tiny does not provide a binary that provides the vim name. By the sysadmin installing one of the other packages, they're no longer working with a base install and have expressed a desire to work with a more featureful Vim package.

As far as your attempt at returning vi's behavior to that of vim-tiny, it is working under incorrect assumptions. Debian (and therefore Ubuntu's) packaging is what causes Vim to run in nocompatible mode by default. This is an intentional deviation from upstream which you eliminate by removing the system-wide configuration files. If you want vi to always follow vim-tiny's behavior, then you can change /etc/vim/vimrc to "set compatible" when v:progname is vi.

Also, your attempt at recovering the behavior after removing the system-wide configuration files is flawed. By simply removing the packages (not purging them), you haven't done anything that affects the conffiles. A package's conffiles are only removed/forgotten by dpkg when you purge a package, not when you remove it. As such, reinstalling the removed packages has no effect on the conffiles you removed by hand. You, as the system administrator, took a specific action of removing the conffiles so dpkg is honoring your action. If you had purged the packages, then dpkg forgets its knowledge about the conffiles and a later reinstall will re-add the standard conffiles.

Revision history for this message
srdjan (srdjan-djenka) wrote :

I'll try to approach this from the slightly different angle:
I think that default vim config has gone backwards. What has been removed is:

* runtime! debian.vim - this one sets up useful behaviour

* if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif
This is very useful for avoiding upgrade conflicts.

Please consider putting those two back

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.