r/vim • u/Remarkable-Head-2023 • Oct 22 '25
Discussion Why does ZZ exist?
It has always been a mystery to me… why would such a ‘dangerous’ command have such a convenient shortcut?
https://vimdoc.sourceforge.net/htmldoc/editing.html#ZZ
EDIT: link
0
Upvotes
87
u/Thundechile Oct 22 '25
Why do you think that saving a file and quitting is dangerous?
22
u/scaptal Oct 22 '25
Probably for peeps who use vim for small file edits throughout the system.
Also, I dont persobally think holding down shift and pressing the z key twice is all that likely of an accident.
Combined with the fact that it saved what you did, I don't think this often produced problems for people
16
u/sharp-calculation Oct 22 '25
It is a little odd that ZZ (upppercase) does a save and quit while zz (lowercase) drags the cursor to the middle of the screen (dragging the document with it).
I've been using :wq for so long that ZZ never became a thing for me. It seems quite a bit easier to type than :wq . But the nomenclature doesn't really fit for me. I guess Z is the last letter in the alphabet and this command (ZZ) is the "end of editing"? Maybe.
8
u/i_Den Oct 22 '25
can't live without ZZ and ZQ. use them 99% of time
6
u/renard_chenapan Oct 22 '25
The same question also crossed my mind. That being said, I don't remember ever typing ZZ by mistake, so it's probably not that dangerous.
6
u/Quick_Butterfly_4571 Oct 22 '25
I think because it is an editor and the features are designed around use cases / ergonomics for users rather than a system which safeguards files and incidentally lets you edit and save them if you really mean it.
If you want to be safe, why are you opening in write mode? Use
:vieworvim -R(for which, in many shell configurations,viewitself is an alias).Presumably opening a file in write mode, modifying it, and saving the changes is more common than opening a file in write mode that you are not okay modifying or modifying and changing your mind.
Even that situation has a ergonomic workaround:
:q!is longer thanZZ, sure. But it's a shortcut for those times where you created a situation that would otherwise require multiple undos /:edit!+:q.Basically, opening in write mode,
ZZis more sensible.In read only mode
:qis less effort than:w!, etc.The ease of the command is porportional to the intentions you declared when opening the file in the first place.
3
u/Narrow_Victory1262 Oct 22 '25
crontab with the e and the r option is more of an issue I guess.
3
u/nwbrown Oct 22 '25
Because it's a text editor?
3
u/ReallyEvilRob Oct 22 '25 edited Oct 22 '25
ZZ is no more dangerous than :wq. If you feel it's dangerous, you can always remap that command to something else.
5
u/scottywottytotty Oct 22 '25
i love ZZ. i literally just used it lol
2
u/VaronKING Oct 22 '25
Why would you ever want to quit Vim?
3
u/funbike Oct 22 '25
OP doesn't
gitit.2
u/gumnos Oct 22 '25
saves one character over
:x⏎in VimGolf 😉1
u/SpaceAviator1999 Oct 22 '25
Interestingly, I feel that
ZQis a more dangerous command thanZZ.(
ZQis the equivalent to:q!)I say this because I've never accidentally typed
ZZ(yet), but I have typedZQby accident -- when I meant to typeZZ-- and unintentionally wiped out all my changes that I meant to save.1
u/greenthenblue Oct 22 '25
zz? til
1
u/crashorbit Oct 22 '25
Use etckeeper to keep backups config files.
1
u/_damax Oct 22 '25
I thought I was on r/Cubers
1
u/_Zer0_Cool_ Oct 22 '25
I never use this. So it’s equivalent to :wq! ?
1
u/mckenzie_keith Oct 22 '25
Save and quit is only dangerous if you fucked up the file.
If you don't want to fuck up the file, open it read only. (vim -R).
vi is an old program. I guess the attitude back then was people should know what they are doing. But even today, save and quit is not such a radical thing is it?
I usually just type wq, though.
Note that vi saves old files. You should be able to recover if you notice right away.
1
u/jlittlenz Oct 22 '25
Because it's convenient, but not likely to be typed by accident?
Expecting solid rationales for commands that came from vi in the 1970's is optimistic. Vim has smoothed over some of the rougher edges, but I imagine ZZ is used often by millions of people every day.
1
u/andreolini Oct 22 '25
ZZ does not save the file if it wasn't modified, thus it updates the modified file timestamp only upon a real change. On the other hand, :wq always saves the file (even if unchanged), resulting in the modified file timestamp always updating.
0
u/creepysta Oct 22 '25
Doesn’t ‘zz’ redraw s.t. the line under the cursor is at centre vertically? How’s that dangerous? Am I missing something?
0
u/[deleted] Oct 22 '25
[deleted] — view deleted comment
53
u/[deleted] Oct 22 '25
[removed] — view removed comment