[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Vi and Emacs

A long treatise on update-alternatives follows...

?smund ?deg?rd <aa@simula.no> [2002-08-12 17:18:31 +0200]:
> If your version of vi is "vim" as it should be, position yourself at the
> beginning of the paragraph and use gq}

Don't get me started on how vim is not a proper alternative
replacement for vi.  It is not.  If you want 'vim' then type in vim.
Or fix vim to be keystroke compatible with vi by default and have an
option to enable vim-mode.

Keith O'Connell <keith_oconnell@blueyonder.co.uk> [2002-08-12 16:22:24 +0100]:
> Your comment puzzles me though 'If your version of vi is "vim" as it
> should be'. Why should it be?

IMNHO it should not be.  Vim has many new and advanced features over
the classic vi program.  People who like vi (and envy the features of
emacs) usually like the vim program since it implements much of the
fun stuff in a vi-style interface.  But the keystrokes are different
so I dislike it as a vi substitute.

> I am in fact using nvi, for no other reason than it is the default
> clone that Debian installs.

A few years ago you would be right.  But today the answer is
complicated for two reasons.  One is the Debian alternatives and the
other is because of a new program called vim which is popularly
installed in place of vi.  Because of that there is no simple answer.
But vim is not the only perpetrator.  On Debian other programs like
elvis might also be masquerading as vi.  A few years ago elvis was as
popular of a vi replacement as vim is today.  It is an equal
opportunity system.  Things change over time.

It used to be that you could always count on vi being available and
usable on any unix system.  Therefore it was the considered the lowest
common denominator.  Sun, HP, IBM, AT&T, BSD, all had vi and except
for very minor differences vi all worked the same across all of those
systems.  Note that those are all proprietary, non-free, systems.  The
problem is what is a free operating system going to do to implement
vi?  Something must be used to replace it and that something can't be
the original vi.  (Can it?  It can if you use nvi.)

The nvi program is as close to this as you can get.  It is based upon
much of the same code but is the 'freed' BSD version of the original
UNIX code.  The proprietary parts of the code were excised.  Therefore
when you learn and use nvi you are really learning and using as close
to the original traditional UNIX vi program as you can get which has
been available on systems for years.  The nvi program *should be* the
default vi program on systems, darn it.  But since free software
systems have to make choices to avoid the proprietary code many have
chosen differently.  Many have chosen to *improve* upon vi instead of
just replace it.  How annoying for those that just want a replacement.
So today learning vi is not standard nor uniform across all systems.

Enter vim.  Vim is a really nice update to vi.  It can only be
described as emacs envy all of the features that has been placed into
the vim program.  It has color, it has syntax highlighting, it has
mode specific indention, it has a kitchen sink of features.  If there
is not a web server in there then there soon will be.  The interface
is based on the vi modal input model.  Therefore vi users can get up
to speed on vim very quickly.

Enter Debian and the 'alternatives' feature.  On Debian there is an
'alternatives' feature which allows a symlink from /usr/bin/program to
/etc/alternatives/program which in turn symlinks off to the real
program.  Many programs are installed as an alternative.  The
'update-alternatives' program is the management tool for this.  Read
the man page for that and it will become clear.

  ls -l /usr/bin | grep alternatives

Lot's of fun stuff there.  This discussion applies to all of those.
But let's look at vi in particular for the moment.

  apt-get install nvi

  update-alternatives --display vi
  vi - status is auto.
   link currently points to /usr/bin/nvi                <- nvi
  /usr/bin/nvi - priority 30
   slave vi.1.gz: /usr/share/man/man1/nvi.1.gz
  Current `best' version is /usr/bin/nvi.

So in this case if only nvi is installed then /usr/bin/vi will be nvi
and all will be good and happy.  But since vi is an alternative
package any program which provides a vi interface can be installed as
vi, replacing other alternatives, by specifying a higher priority.
The priority for nvi is 30.  (This is too low IMNHO.)

The elvis program considers itself to be a vi alternative.  The
priority for elvis is 120.  The highest priority wins.  If you install
elvis with 'apt-get install elvis' it will push out nvi as the default
vi on the system and replace it with elvis.

  apt-get install elvis

  update-alternatives --display vi
  vi - status is auto.
   link currently points to /usr/bin/elvisnox           <- elvis
  /usr/bin/nvi - priority 30
   slave vi.1.gz: /usr/share/man/man1/nvi.1.gz
  /usr/bin/elvisnox - priority 120
   slave vi.1.gz: /usr/share/man/man1/elvis.1.gz
  Current `best' version is /usr/bin/elvisnox.

The vim program is such a nice update that vim users want to make vim
the default replacing the vi program too.  The priority for vim is 120
which is the same as elvis.  The highest priority wins.  When you
'apt-get install vim' it will push out nvi as the default vi on the
system and replace it with vim.  But since the priority is the same as
elvis it won't push out elvis.  Those two have equal priority and the
priority must be greater to push out another package.

  apt-get install vim

  update-alternatives --display vi
  vi - status is auto.
   link currently points to /usr/bin/elvisnox           <- still elvis
  /usr/bin/nvi - priority 30
   slave vi.1.gz: /usr/share/man/man1/nvi.1.gz
  /usr/bin/elvisnox - priority 120
   slave vi.1.gz: /usr/share/man/man1/elvis.1.gz
  /usr/bin/vim - priority 120
   slave vi.1.gz: /usr/share/man/man1/vim.1.gz
  Current `best' version is /usr/bin/elvisnox.

Now you have all three installed.  You have nvi, elvis, and vim.  The
alternatives point to elvis.  But what if we remove elvis?  Again,
highest priority wins.  Since vim has the highest remaining priority
it will win and will become the default /usr/bin/vi.

  apt-get remove elvis

  update-alternatives --display vi
  vi - status is auto.
   link currently points to /usr/bin/vim                <- vim
  /usr/bin/nvi - priority 30
   slave vi.1.gz: /usr/share/man/man1/nvi.1.gz
  /usr/bin/vim - priority 120
   slave vi.1.gz: /usr/share/man/man1/vim.1.gz
  Current `best' version is /usr/bin/vim.

And if I were to remove vim from the system as well the alternatives
would be returned to the original nvi.  I hope this tour of the
alternatives is useful.  It is a really cool feature that has been
unique to Debian.  (But I hear that parts of it are flowing to other
distributions such as RH now.)  Okay, enough of that, now let's bash
vim some more.  :-)

However, vim is not the same program as vi and the keystrokes are not
100% compatible.  Which means that some things you do in vi you need
to do differently in vim.  Which frustrates a user like myself which
does not want to switch up to vim but just wants to use the same old
traditional vi program keystrokes that I have been using for years.

But I can customize the Debian system as is my choosing.  Which is
what I always do on my systems.  I use the update-alternatives program
to configure the alternative vi program.  [This does not remove vim
from the system.  I work with people who use it.  It only makes vi be
the real vi.  Any vim user just needs to call vim as vim and they get
vim.  And they always call it vim because on non-debian systems they
need to and have taught their fingers that.]

  update-alternatives --config vi
  [...enter 1 to choose nvi...]

  update-alternatives --display vi
  vi - status is manual.                       <-- now manual
   link currently points to /usr/bin/nvi
  /usr/bin/nvi - priority 30
   slave vi.1.gz: /usr/share/man/man1/nvi.1.gz
  /usr/bin/vim - priority 120
   slave vi.1.gz: /usr/share/man/man1/vim.1.gz
  Current `best' version is /usr/bin/vim.

This will stick.  It is also permissible to manually modify the
symlinks.  Both will set the status to manual and your choices will
not be overwritten.  And not mentioned previously note that the man
pages are also changed to track the actual underlying binary.  A
really clever system.

> I want to be able to sit at any linux/unix terminal and at least be
> guaranteed to be able to use an editor.

Sorry.  While that used to be true before alternatives (and vim or
elvis or editorxyz) it is not true any longer.  Now you will never be
able to tell if you are calling vi or if you are calling something
that is masquerading as vi through alternatives.  Hopefully any
doppelganger using alternatives will be keystroke compatible at the

> Why Vim? Why does Debian default to Nvi?

It is all set in the priorities set in the individual packages.  This
is not a global setting.  It is dependent upon the packages installed.
Which at the source might be what you asked for in 'tasksel' at
install time or in 'dselect' or other method used to install and
upgrade your system.  You would not have vi at all if you never
installed any of them.  If you installed only nvi then you get nvi.
If you installed vim then vim pushed out nvi.  If you installed elvis
then elvis pushed out nvi.  Between elvis and vim it was the first one

It is probably too late to fix my complaint about nvi having a
priority of only 30 while the other fakers have a higher priority.  As
frustrating as it is things like editors are too much an autonomic
response.  Which makes it impossible to make separate intelligence
based decisions from emotional decisions.  You will just have to learn
to live with the differences.  Sigh.

> What is the "realistic"lowest common denominator on machines?

As far as I know there is still 'ed'.  :@) [Don't laugh too hard.  I
wrote thousands of lines of code using 'qed', a similar program.  If
my terminal is broken I can fall back to ed to fix things and then go

I personally would recommend learning emacs.  It is the ultimate text
editor and word processor.  But users are fanatical about their
editors and the emacs versus vi wars over years have been legion.
Don't expect to get an unbiased recommendation from anyone.


Attachment: pgpkgXUzH5giW.pgp
Description: PGP signature

Reply to: