Frequently Asked Question

How do I actually exit Vim?

The classic trap: you opened vim to read a file, you cannot type anything sensible into it, and you cannot work out how to leave. The escape hatch is three keystrokes. Press Esc (this guarantees you are in normal mode, no matter what mode you wandered into), then type :q! and press Enter. The colon enters command-line mode, q means quit, and the ! says discard any unsaved changes. The whole machine survives intact.

If you do want to save first, the usual variants are :w (write), :wq (write and quit), :x (write only if changed, then quit), and ZZ in normal mode (the same as :x but without the colon). The :q form on its own only succeeds if you have made no changes; if you have, Vim refuses and prints an error, which is what the ! is for. None of this is intuitive the first time, but it is muscle memory by the third.

The reason this question is famous, Stack Overflow's "How do I exit Vim?" has been viewed millions of times, is that Vim's modal design means letters typed at the keyboard are commands, not text. Almost every other program puts you straight into "type text" mode, so the convention does not transfer.

Video

Further reading and video