[oak perl] vi: materials, tab conversions, etc.
Michael.Paoli at cal.berkeley.edu
Sun Jun 18 16:25:04 PDT 2006
At the last Oakland Perl Mongers meeting, a couple folks asked about
vi materials and tab conversion in vi, so, thought I'd mention some
materials and such ...
This is probably the earliest fairly well known introduction to vi:
An Introduction to Display Editing with Vi
Classic (/"old"), but still generally quite useful, and
relatively/comparatively short (27 pages):
The PDF better reflects the "original" format, but there's also the
HTML version (multiple pages with links):
(Google conversion of the PDF to HTML is formatted more like the PDF,
and ends up as a single document, but then doesn't have the links
within the document)
O'Reilly ("of course") has a great book on the topic:
Learning the vi Editor Sixth Edition
Don't know that it's supposed to be online (other than Safari), but
looks like someone's got it out there, at least at the moment:
... glancing at it a bit, it does (unsurprisingly) look very well put
together and quite thorough and comprehensive. So, ... if you think
it's a good book, and want to have it, buy it :-) ... you did get a
bookmark too, right?
A quite good starting point for finding all kinds of vi materials and
Vi Lovers Home Page
There are lots of good vi reference cards out there:
I'm most familiar with this classic ("old") version ... or an actual
classic ("old") tri-fold hard copy card version of it I actually have.
It's designed to work as a tri-fold card, 8.5x11" double sided
There's an HTML version too, but it looks like it was a poor
conversion from the source documents:
Actually Google's conversion from PDF to HTML turns out much better.
There are lots of vi(1) variants. Most notably, nvi(1) and vim(1)
mostly add a fair bit to a lot of stuff to the original vi(1)'s
functionality. On BSD flavors, nvi will generally be in place as the
"vi" editor, on LINUX one will frequently find vim or nvi in place for
the "vi" editor. nvi and vim have distinct design goals, ... nvi is
highly vi compatible, vim adds lots of bells and whistles, but isn't
as compatible (keystroke sequences in vim are sufficiently different
that vim often slows me down significantly, as my well trained vi
fingers quickly spew out sequences of actions for vi, and, well, ...
vim just doesn't work quite the same way, and I end up backtracking
and/or repeating stuff, or having to review it again to figure out
what the heck vim actually did in response to my vi commands).
Nvi - 4.4BSD re-implementation of vi
"Vi is the original screen based text editor for Unix systems. It is
considered the standard text editor, and is available on almost all
Unix systems. Nvi is intended as a 'bug-for-bug compatible' clone of
the original BSD vi editor."
The original vi editor couldn't be freely redistributed - most notably
it contained ed(1) code in it that couldn't be freely redistributed.
Hence when the BSDs forked cleanly from the UCB UNIX/BSD mix, nvi was
born. Nvi is highly compatible with vi, but nvi fixed some
bugs/limitations in vi, and added some small bits of additional
The O'Reilly book spells out some of nvi's differences/additions, but
these are the key ones I note, and also why I prefer nvi to vi:
1022 character line length max not a problem
can't handle null characters not a problem
can't handle lines that are too not a problem
long to display on screen
lines longer than screen width has cool leftright option to scroll
are always displayed folded sideways, instead of displaying
Historically, vi also had some other problems/bugs (e.g. couldn't
write a zero length file, couldn't handle fairly large (>~=10 MiB)
files, etc.), but those issues/bugs are also gone from non-ancient
versions of non-free vi, but the other issues/limits/bugs I note
I think vim, nvi, and most(/all?) vi clones omit including the old
crypt(1) functionality which is built-in to the non-free vi(1)/ex(1)
(or at least were in certain US export restricted versions).
The encryption of crypt(1) (not to be confused with crypt(3)) is
rather/quite weak anyway, so that's not much of an issue, ... and
there are freely available (re)implementations of crypt(1) these days
anyway, so if one really wants to use crypt(1), it can be invoked as
a filter from within vi/ex, it just won't get automagically used on
every read/write by setting the key once, and it probably won't cover
editor temporary files.
I could probably easily do a whole article of various things in vim
that annoy me, but probably >~=90% of vim users wouldn't be annoyed by
these things, wouldn't notice them, and/or would consider them a
"feature" ... so I think I'll skip that.
nvi isn't completely and totally free of bugs and such, but I think
it's effective bugs/limitations at this point are sufficiently few and
small that it's well past the point where it outperforms vi in these
regards. I can think of a few tiny things in nvi that annoy me a bit,
but I consider these less of an annoyance than the functional
limitations that still exist in non-free vi.
converting from tabs to spaces (or vice versa., etc.)
vi isn't an operating system, it's a text editor. You can change
tabstop width and shift width in vi, how tabs are displayed, etc., but
it doesn't convert tabs to spaces or vice versa. But on a
UNIX(/LINUX/BSD/...) operating systems, that's easy to do within vi,
by using expand(1) or newform(1), e.g. go to first line of file, in
command mode then type:
followed by <RETURN> or <ESC> or <NEWLINE>
expand can be replaced with the specific desired conversion/filter
expand -t 4
expand -t 2
and the process can likewise be essentially reversed, with unexpand(1)
or newform (-o [...]).
Using pr(1) may be another approach.
In general, in vi, using ! and a cursor motion command, then entering
a command, will take the text that would be traversed by the cursor
motion command, pipe it through the command, and replace the text with
the output of the command. In vi, that cursor motion command needs to
involve more than one line, or go through to the beginning or end of
file, but that limitation isn't the case with nvi and vim (where the
cursor motion can be quite arbitrary, including just within a line).
Vim also has other tab related options and commands present in neither
vi nor ni, e.g.: expandtab retab smarttab softtabstop
"Emacs is a great operating system---it lacks a good editor, though."
$ ls -flL /bin/ed /usr/bin/vi /usr/bin/nvi /boot/vmlinuz \
> /usr/bin/vim /usr/bin/emacs
-rwxr-xr-x 1 root root 39544 Apr 2 2003 /bin/ed
-rwxr-xr-x 3 root root 360760 Mar 6 2005 /usr/bin/vi
-rwxr-xr-x 3 root root 360760 Mar 6 2005 /usr/bin/nvi
-rw-r--r-- 1 root root 837152 Jan 26 2005 /boot/vmlinuz
-rwxr-xr-x 1 root root 1411096 Jul 30 2005 /usr/bin/vim
-rwxr-xr-x 1 root root 4465716 Mar 17 2005 /usr/bin/emacs
news:D4qEzA.3xu at demon.co.uk
news:3i1str$am4 at crl4.crl.com
More information about the Oakland