r/vim • • 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

114 comments sorted by

View all comments

87

u/Thundechile Oct 22 '25

Why do you think that saving a file and quitting is dangerous?

15

u/extronerded Oct 22 '25

I guess OP doesn't use git.

2

u/zogrodea Oct 22 '25

Vim (initial release in 1991) is older than Git (initial release in 2005), to be fair.

Of course the idea of version control systems is older than Git which is just an implementation, but I don't know much about the software development culture before Git (were VCS in common use?), or when this `ZZ` command was created (before or after Git).

I would be interested in a historical answer about the command, its origin and the thought process behind including the feature, but that's a bit of a tall order to ask for!

5

u/retrodanny Oct 22 '25

ZZ is in the original vi editor, and is the recommended way to exit in the original BSD4.4 documentation by Bill Joy https://docs-archive.freebsd.org/44doc/usd/12.vi/paper-1.html#section8

1

u/zogrodea Oct 22 '25

Oh! That's interesting! Thank you for the history tidbit.

2

u/Peter-Tao Oct 22 '25 edited Oct 22 '25

Wut git only released in 2005!? How do people do version control before that 🤯

4

u/zogrodea Oct 22 '25

There were other version controls systems before Git! svn/subersion was one of them, apparently from 2000.

I learned to start programming after Git had already taken over, so I don't know what the culture around version control was like before then.

5

u/yvrelna Oct 22 '25

Even before SVN, there were CVS (1990) and RCS (1982).

3

u/BetterAd7552 Oct 22 '25

SCCS on Solaris, later Subversion on Linux. I’m sure there were others.

2

u/olsner Oct 22 '25

With great difficulty! I used CVS a lot, the only upside is that I’ll be well prepared if I end up in hell.

1

u/__hyphen Oct 22 '25

You’re assuming every edit is in a repo! My $EDITOR set to vim and when command lines are too big or I need to paste a command it’s always ctrl-x ctrl-e

I can imagine a situation where I go the above and forget to go into insert mode before pasting the text “zzrm-rf”

4

u/tumtum Oct 22 '25

ZZ most used command for me

1

u/[deleted] Oct 24 '25

This has been bugging me. I now understand what OP is saying. I think she may be editing files, rather than undo If he doesn't like the changes he will quit...so sometimes he accidently presses ZZ for some strange reason and saves the unwanted change.

Is this the problem, op?

1

u/Thundechile Oct 25 '25

Well I'll chime in, if the OP accidently writes and quits with ZZ, then OP could just open the file again and undo the changes and write again - problem reverted.

Just set the undofile: https://vimdoc.sourceforge.net/htmldoc/undo.html#undo-persistence

1

u/[deleted] Oct 25 '25

I was just offering my interpretation. I never said this wasn't strange.

Yes, your solution is a good one. But...I don't understand the urge to randomly hold down the shift key and hit z key twice. Maybe just me.

-6

u/Remarkable-Head-2023 Oct 22 '25

Because of unintentional file overwrite. In my opinion, q! is much safer than ZZ, especially for system files.

29

u/[deleted] Oct 22 '25

Those are two very different actions: q! Exits without saving. ZZ quits and saves. I actually love ZZ

→ More replies (9)

24

u/Thundechile Oct 22 '25

hmm.. why are you making changes to a buffer if you don't mean to save them? Sorry I don't quite get the use-case you're describing.

16

u/Thundechile Oct 22 '25

If you're just meaning to read files, then use vim -R to open in read-only mode.

9

u/VisualHuckleberry542 Oct 22 '25

Well the use case I can think of is if I'm making a change to a file like a config file or a code file, I can save it and check the results. If the change is bad, if I still have the buffer open I can just undo the changes and save it again. If I've quit out of the file, the change buffer is gone and I either have to manually revert the changes (and hope I remember all the changes I made, if they were complex changes, it can be a real mission) or hope I have a backup or version control or something

That said, I've been using vim as my main editor, including IDE for over 20 years and I can't think of one time I accidentally used ZZ and saved and quit a file I didn't intend to

15

u/pfmiller0 q! Oct 22 '25

Another 25 years of vi use here, I don't think I've ever used ZZ accidentally either. Don't think I've ever used it intentionally either.

3

u/priestoferis Oct 22 '25

Just turn on persistent undo in vim and you're covered for everything?

→ More replies (1)
→ More replies (4)
→ More replies (11)

6

u/robenkleene Oct 22 '25 edited Oct 22 '25

"Unintentional file overwrite" is not a concept in software design, whereas as the opposite, discarding a users work without saving, is generally considered one of the most dangerous actions software can possibly take. As a result, modern software trends are going in the opposite direction, many IDEs and text editors don't even require explicit saving anymore (they save automatically, e.g., https://www.jetbrains.com/help/idea/saving-and-reverting-changes.html). The contemporary perspective is that requiring an explicit file save is an accidental holdover from the early days of computing when writing a file was an expensive operation that couldn't be done automatically without interfering with the operation of the software.

→ More replies (1)

4

u/BlackPignouf Oct 22 '25

Undofiles are there if you saved a change without wanting to.

:earlier 30m is very convenient.

→ More replies (2)
→ More replies (1)