Sometimes when I do a filter-through-especially on some buggy, old
versions of vi
-it completely scrambles and trashes my text.
Things can be so bad that the u
(undo) command won't work.
Unless I've been careful to write my buffer (with
before the filter-through,
I can lose the whole file!
I've seen the same problem on several versions of vi
articles on Usenet from people who've been bitten by it.
If you've been burned, too, you might want to use the
Map one of your keys - a numbered function key like F4, if you can - to do
filter-throughs of your whole file.
To start a filter-through, press the F4 key - this invokes the first
Next, type the UNIX command you want to run.
To run the filter-through, press F4 again.
The maps are shown here:
enter the control characters
by typing CTRL-v first (31.6
map #4 :se noaw^M:w^M:%d^M:r !
map! #4 ^V '%'^M:1d^[:se aw^[
The first one (
) maps the F4 key during command mode to
set the noautowrite
), write the buffer to
your file (
), delete all lines in the buffer (
and start a shell command line
After pressing F4 from command mode, your cursor should be on the bottom
line, ready for you to type the filter-through:
Type the UNIX command (like
, and so on).
Then press F4 again.
Because you're in text-input mode, the second map above (
will be used this time.
The map starts with CTRL-v and a space; this trick puts a space between
the command line you type and the filename.
Next, the current filename
-in single quotes, to protect
special characters from the shell - is output, followed by a RETURN
to execute the command.
Reading a UNIX command with
leaves a blank line above;
deletes that line (it'll be the line 1 in the buffer).
command turns on the autowrite
If you never set the autowrite
option, you can leave out the
But be sure - if autowrite is set when you use this map, all lines in
your file will be deleted!
(The empty buffer will be auto-written when the shell command runs.)
I guess it figures
tricky set of keymaps doesn't work perfectly on
every version of vi
On my old SunOS 4.1 version of vi
, for instance, it left me in text-input mode;
I had to hit ESC after pressing F4 the second time.
Still, this is a lot more reliable than the normal way to do
filter-throughs on buggy versions of vi
It's been especially nice because I've always been able to undo the
filter-through with the u
haven't used these keymaps in several years, but filter-throughs are
such an important vi
feature to me that I'll always keep them handy.