[comp.editors] that old vi write bug

dattier@vpnet.chi.il.us (David W. Tamkin) (04/15/91)

A while back I posted something that really annoyed me about vi.  If you're
running an application (especially sending mail) and it creates a temporary
file for you to edit, but you'd like to keep a copy, and you write out the
buffer to another file name with ":w file", vi clears the [Modified] flag.
If you make no further modifications before exiting vi with :x, ZZ, or in
some implementations even :wq, all changes that were included in the spare
copy are lost in the one that will get mailed, because if the [Modified] flag
isn't set, :x, ZZ, and sometimes even :wq will think no writing needs to be
done and will simply exit.

One has to remember to :w<cr>:q in that circumstance.  If the letter is not
one that can be stopped with uustat -k, or if you don't realize what you did
and don't try to stop the letter, a partly finished letter will go out
instead.  In some cases, if you didn't type :w at any time during the edit
except when you saved the copy, you've mailed out a textless letter or sent
your correspondent's own words back to him or her with citation marks down
the left margin.

I found a workaround, though; it is one that doesn't require me to remember.
I've mapped ^W (which backs up one word in input mode but is unassigned in
command mode) to ":%!tee<space>".  It waits on the command line for me to
type a filename (or -a filename).  The extra benefit is that, even though I'm
replacing the buffer with its own current contents, vi doesn't know that tee
makes no changes, so it forcibly SETS the [Modified] flag and makes sure I'll
get a full write when I exit (unless I use :q!).

One could map ^W to :w^M:w<space>, I suppose, and get almost the same effect.
The [Modified] flag is cleared by that operation, but the application's
temporary file is updated with the changes so far, so at least if one does
fall into the original trap later in editing the document, one has sent a
partly edited file instead of an unedited one.

Considering the problems I sometimes have with
:{range}w file
:{range}w! file  and
:{range}w >>file
on partial ranges, I'll stick with :{range}!tee [-a] file for those.

David Tamkin  PO Box 7002  Des Plaines IL  60018-7002  dattier@vpnet.chi.il.us
GEnie:D.W.TAMKIN  CIS:73720,1570  MCIMail:426-1818  708 518 6769  312 693 0591