How to Exit Vim (and Why It Traps People)

September 2, 2026 in Vim3 minutes

Everyone knows :q by now. The reason people still get stuck is that Vim refuses to quit and the error scrolls past unread.

It is the oldest joke in software, and it is still the single most searched question about this editor.

The answer is :q. But if that were the whole story nobody would still be stuck, so let us do the version that actually helps.

First, the escape hatch

Vim has modes. If you have been typing text, you are in insert mode, and :q will not do anything useful because the : just gets typed into your file.

Press Esc first. Always press Esc first.

If you are unsure what mode you are in, press Esc twice. It is harmless.

The five commands

CommandWhat it does
:qquit, if you have no unsaved changes
:q!quit and throw away your changes
:wsave, stay in the file
:wqsave and quit
:xsave and quit, but only writes if something changed

Each needs Enter after it.

There is also a keyboard shortcut version with no colon: ZZ saves and quits, ZQ quits and discards. Capital Z, twice. Handy once your fingers know it.

Why :q sometimes refuses

Here is the bit that traps people. You press :q, hit Enter, and nothing happens. It looks broken. It is not:

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

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

That is Vim saying: you changed this file and have not saved it, so I am not going to let you lose your work by accident.

You have three choices, and it is worth knowing which one you want:

  • Save and leave:wq
  • Leave and bin the changes:q!
  • Actually I want to stay → press Esc and keep working

The exclamation mark means “I know, do it anyway”. That meaning is consistent across Vim, so it is worth internalising early.

The other one that catches people

If you opened several files, :q closes one window, not the editor. When another file is still open, it can feel like Vim is refusing to die.

:qa quits all of them. :qa! quits all and discards everything.

The two-second summary

Esc, then :wq to save and leave, or :q! to leave and throw it away.

That is genuinely all you need on day one.

And the part worth saying

The reason this question is a meme is not that Vim is badly designed. It is that Vim is the only common editor that assumes you will learn it, and gives you almost nothing until you do.

That is a real trade. What you get in return is an editor where the effort you put in keeps paying off for the next twenty years, on every machine you ever ssh into, without a mouse.

The exit is the first small tax. Everything after it is the refund.


If you are past the exit and want the rest: Vim & Neovim Mastery, Build a Modern IDE From Scratch starts from a bare terminal and builds up to a full modern setup, with every keystroke on camera.