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

← All Vim commands · Vim cheat sheet