file

: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.

:q   :q!  (command mode)

Variations

Keystroke Effect
:qa Quit ALL windows / buffers
:qa! Quit all, discard every unsaved change
:cq Quit with error code (useful when Vim is a $EDITOR — aborts the commit/rebase)

Examples

:q

Close current window

:q!

Force quit, throw away unsaved edits

:qa!

Bail out of an entire Vim session

Gotcha

:q refuses to quit if the buffer is modified — you'll see 'E37: No write since last change'. Use :q! to force it, or :wq to save first.

Related

← All Vim commands · Vim cheat sheet