How to exit Vim (and what E37 means)
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.
- Press Esc, maybe twice, to be sure you're in normal mode.
- Type a quit command and press Enter. It appears at the bottom of the screen as you type.
| Type | Does |
|---|---|
:q | quit, 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.
Your task
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.
- Try :q on a changed draft.txt (E37) (not done yet)
- Leave draft.txt without saving (not done yet)
- Add the line to notes.txt, save and quit (not done yet)
The checklist ticks itself off as you work in the terminal: any way that gets the result counts.
Hints come one at a time, then one way to do it. Try each before the next.
What this lesson uses, in one place.
:q- Vim: quit, if nothing has changed (E37 if it has)
:wq- Vim: save and quit
:q!- Vim: quit and throw away the changes
ZZ- Vim: save and quit, in two keys
Every everyday command on one page: the Linux commands cheat sheet.