file
:wq / ZZ
Write the buffer to disk and quit the window. ZZ (normal mode, two capital Zs) does the same thing without leaving the keyboard's home row — with the subtle difference that ZZ only writes if the buffer actually changed.
:wq ZZ (command / normal mode) Variations
| Keystroke | Effect |
|---|---|
| :x | Almost identical to :wq but only writes when there are changes |
| :wqa | Write and quit ALL windows |
| ZQ | Normal-mode equivalent of :q! — quit without saving |
Examples
:wq Save and quit
ZZ Save (if modified) and quit without a colon-command
:wqa Save every buffer and exit Vim
Gotcha
:wq updates the file's mtime even with no changes, which can trigger unnecessary rebuilds — use :x or ZZ if you rely on modification times.
Related
:q / :q!
:q closes the current window (or exits Vim if it's the last one); :q! quits and DISCARDS unsaved changes. If you're the 'how do I exit Vim' meme — this is the answer.
:w / :saveas
Write (save) the current buffer to disk. Without an argument :w saves to the current file; with an argument it writes a copy without switching buffers. Use :saveas when you want to rename the buffer to the new file and keep editing that one.
:e
Edit (open) a file in the current window. With no argument, :e reloads the current file from disk — handy after external changes.