Press Escape. Then type :q! and press Enter. You're out.
If you want to keep your changes, use :wq instead — write, then quit. If you haven't changed anything, plain :q works. That's the whole answer, and you deserved to get it in the first line rather than after nine paragraphs about a text editor's philosophy.
Now the interesting part: why couldn't you work that out on your own? You're a developer. You solve harder problems before lunch. But this one editor put you in a box with no visible exit, and the escape hatch turned out to be a punctuation mark.
You were typing into the file
Here's what almost certainly happened. Vim opened. You typed q, quit, exit, :x, ctrl-c, ctrl-z, and finally closed the terminal window.
Every one of those keystrokes went into your document. Not to the editor — into the text. Vim wasn't ignoring you; it was obeying you, letter by letter, and you were writing the word "quit" into a file you never meant to edit.
That's because Vim starts in normal mode, where keys are commands, not characters. Most editors have exactly one mode: everything you press appears on screen. Vim has several, and typing text is only one of them. The moment you understand that, :q! stops being a magic incantation and becomes an ordinary sentence.
What :q! actually says
Break it apart:
:opens a command line at the bottom of the screen. It means "I'm about to give an instruction, not type a letter."qis quit.!means force — do it even though I have unsaved changes.
So :q! is "quit, and yes, I'm sure, throw away my edits." It reads like a sentence because it is one. Vim's commands compose out of small pieces with fixed meanings, which is the single most useful thing to know about it.
:wq reads the same way: write, quit. :w on its own saves without leaving. There's no memorization here, only grammar.
Escape first, always
The reason Escape comes first in every recipe: it returns you to normal mode from wherever you are. If you were in the middle of typing, Escape stops that. If you started a command and changed your mind, Escape cancels it.
When you're lost in Vim — and you will be, for about a week — the answer is nearly always Escape. It's the "I don't know where I am" key, and it costs nothing to press twice.
This is the joke, and also the point
"How do I exit Vim" is one of the most-viewed questions in Stack Overflow's history. It's a running joke in every developer community on the internet. There are t-shirts.
But look closer at what the joke is really about. Nobody is stuck because Vim is badly built. They're stuck because Vim assumes something no other editor assumes: that you'll spend more time changing text than typing it fresh. Once you accept that assumption, modal editing is not merely defensible — it's the reason people who learn Vim tend to keep using it for twenty years.
The exit is famous because it's the first place that assumption bites. It's also the last, if you spend an afternoon learning the grammar behind it.
Now do it on purpose
Knowing :q! isn't learning Vim. But it's a real command, and typing it deliberately — instead of panicking — is the first time you'll feel the editor answer you rather than fight you.
Start with the first kata. It takes about a minute, it runs in your browser, and nothing you do there can trap you in a terminal.