In vi, ZZ is not :wq

Robert Elz kre at munnari.OZ
Sat Sep 14 16:09:08 AEST 1985


In article <269 at mot.UUCP>, al at mot.UUCP (Al Filipski) writes:
> ZZ is NOT equivalent to either :wq or :x on our System V.2 vi,
> vi foo
> <change some things>
> :w bar
> ZZ
> 
> does NOT cause the changes to be written to foo.
> 
> ZZ apparently tries to be smart and avoid unnecessary writes,
> but I would expect it to write the file being edited in the case 
> above. A bug, I'd call it.

Wrong.  ZZ writes the file in exactly the same cases as ":q"
would say "file modified and not written" and not exit.  Its
a shorthand for people who get tired of that message, but don't
want to get into the habbit of ":wq" (or ":x") every time they
want to exit (which write the file every time, changed or not).

The relevant point is that ZZ will not write the file if the
changes exist somewhere - they may not be in the original file
that you edited if you saved them elsewhere (but when I do
this, I usually (99% of cases) DON'T want the changes written
back to the original file) - but they do exist somewhere (maybe
/dev/null if you did a ":w /dev/null" which is a useful technique
at times).

This discussion started when someone reported that after a "vi -r"
an immediate ZZ would lose the file (not write it).  That was a bug,
and is fixed in 4.3 (simply a matter of the "changed" flag not being
set after a "recover" operation), ":q" would have silently exited in the
same circumstances.

Robert Elz		seismo!munnari!kre   kre%munnari.oz at seismo.css.gov



More information about the Net.bugs mailing list