Learn Vim / How to Exit Vim

How to Exit Vim

The answerPress Esc to make sure you're in normal mode, then type :q and press Enter. Unsaved changes? :q! discards them, :wq saves them.

The most famous stack-overflow question in history has a three-keystroke answer. The reason it stumps people: vim is modal — if you're in insert mode, ex commands are just text. Esc first, always.

All the ways

KeysWhat it does
:qquit (fails if there are unsaved changes — that's a feature)
:q!quit and discard changes
:wqwrite (save) and quit
:xsave and quit, but only writes if changed
ZZsave and quit — no colon needed
ZQquit without saving — no colon needed
:qaquit all open windows

Reading about keystrokes doesn't build keystrokes. Try this in a real vim buffer right now — the “The stray key” mission takes about a minute.

Practice free — no signup →

Keep going