How to quit Vim

:q:q!:wqZZ

Press Esc, then type :q and press Enter. If you haven't changed anything, Vim quits.

If you have changed something, Vim won't quit until you say what should happen to your changes. Type :q! to throw them away and quit, or :wq to save them and quit. :x and ZZ also save and quit.

Worked example

You opened a file to read it and you want to leave. You haven't changed anything.

Esc:qEnter
Your textVim mode: Normal
You opened a file to read it and you want to leave. You haven't changed anything. Before: Buy milk / Call the bank. After: Buy milk / Call the bank.

Esc puts you back in Normal mode, in case you were typing. Then Vim closes and the file is just as it was.

Commands

:q
Quit, as long as you have no unsaved changes.
:q!
Quit and throw away your changes.
:wq
Save your changes, then quit.
:x
Save if you changed something, then quit.
ZZ
The same as :x, with no colon and no Enter to press.

What E37 means

If you type :q after changing the file, Vim stays open and shows E37: No write since last change (add ! to override). It's stopping you from losing your changes by accident.

So decide what you want. :wq saves your changes and quits. :q! quits without them. The ! is the "override" the message means.

Quit every window

With more than one window open, :q closes only the window you're in. :qa quits all of them at once, and :qa! quits all of them and throws away every change.

:qa
Quit every window.
:qa!
Quit every window and throw away all changes.

Exceptions

  • After a change, :q doesn't quit. You get E37 and your changes are still there.
  • :qa won't quit either while a file has changes. The message is E162 this time, and :qa! is the way out.
  • With two windows open, :q closes one of them and Vim keeps running.
  • If :q shows up in your file, you were still in Insert mode. Press Esc and try again.
  • This site's editor runs in your browser, so these commands have nothing to quit here. To leave a lesson, just go to another page.

Try it