Skip to content

How to exit Vim (and what E37 means)

IntermediateLesson 29 of 666 min

Exit Vim every way: :q, :wq, ZZ and :q! to throw changes away, and what “E37: No write since last change” means. Practise in a Vim in your browser.

"How do I exit Vim?" is one of the most asked questions in programming. The answer is two steps.

  1. Press Esc, maybe twice, to be sure you're in normal mode.
  2. Type a quit command and press Enter. It appears at the bottom of the screen as you type.
TypeDoes
:qquit, if nothing has changed
:wq (or :x, or ZZ with no colon)save, then quit
:q! (or ZQ)quit and throw your changes away
:qa!quit every open file, throwing changes away

E37: No write since last change

Change a file and try :q, and Vim refuses:

E37: No write since last change (add ! to override)

It isn't broken; it's protecting your work. Decide: :wq to keep the change, or :q! to lose it.

Other things that look like being stuck

  • "Press ENTER or type command to continue": Vim showed a message. Press Enter.
  • "recording @q" at the bottom: you pressed q, which records a macro. Press q again to stop.
  • Ctrl+C doesn't quit Vim. Esc, then :q, does.
  • git opened Vim for a commit message: type the message (i first), then Esc and :wq.

Your turn

Open draft.txt, change anything in it, and try to leave with :q: Vim stops you with E37. Leave without saving instead. Then open notes.txt, add a last line that says Esc first, then :wq, and leave saving your work.

Next