How to Exit Vim
Trapped in Vim? You're not alone — it's one of the most-searched questions in programming. Here are all 4 ways to get out, explained.
Quick answer
:qQuit (no changes)
:q!Quit, discard changes
:wqSave and quit
ZZSave and quit (fast)
1
2
3
4
# notes.txt — you opened this by accident
and now you are trapped inside Vim.
type :wq then press Enter to escape.
:wq
The 4 Ways Explained
:q
Quit — No changes, or already saved
Press Esc → type :q → Enter
:q!
Force Quit — Changes made but you do NOT want to save them
Press Esc → type :q! → Enter
⚠️ All unsaved changes are lost.
:wq
Write and Quit — You want to SAVE changes then leave
Press Esc → type :wq → Enter
Shortcut: ZZ (capital Z twice in Normal mode)
ZZ
Save and Quit (shortcut) — Same as :wq, but faster
Press Esc → type ZZ (no colon, no Enter)
Why is Exiting Vim Hard?
Vim is modal. When you open it you land in Normal mode, where keys are commands, not text. So typing "quit" doesn't quit — it runs a string of motions. To leave you first return to Normal mode with Esc, then enter Command mode with : and type a real Ex command like q or wq. Once the modes click, exiting is trivial.
Step-by-Step Guide
- Press Escape. Hit the Esc key to make sure you're in Normal mode. If you were typing, this leaves Insert mode. When unsure, press it a couple of times.
- Type your exit command. Type :q to quit, :q! to discard changes, or :wq to save and quit. The text appears at the bottom of the screen.
- Press Enter. Press Enter to run the command. Vim closes and you're back at your shell.
Want to actually stop fearing Vim?
Learn modes, motions, and editing properly through interactive challenges — no install required.
Master Vim properly →