How do I save and quit Vim quickly from normal mode without typing a colon command?
Answer
ZZ
Explanation
ZZ is a normal mode shorthand that saves and quits only if the buffer has been modified. Unlike :wq, which always writes to disk (updating the file's modification timestamp even if nothing changed), ZZ behaves like :x — it skips the write entirely when the buffer is clean. The companion command ZQ quits unconditionally without saving, equivalent to :q!.
How it works
ZZ— write buffer only if modified, then close the window. Equivalent to:xZQ— quit without saving, no questions asked. Equivalent to:q!
Both commands are two-character normal mode sequences starting with Z. They work on the current window and obey the same rules as their : equivalents.
Example
# Buffer has no unsaved changes:
# :wq → writes the file anyway (updates mtime)
# ZZ → exits without touching the file
# Buffer has unsaved changes:
# ZZ → saves, then exits
# ZQ → exits immediately, discarding changes
Tips
- Prefer
ZZover:wqin scripts or macros when you want to avoid spurious timestamp updates on unmodified files ZQis useful when you opened a file by mistake and want to get out fast without the:q!dance- Both commands close only the current window; if other windows are open, Vim stays running