How to Exit Vim / Vi Editor (Save, Quit Without Saving & Force Quit)
Error Message
Stuck inside Vim or Vi editor after running git commit
Quick Fix
Press Esc, then type :wq and press Enter
Why Does This Happen?
Vim is a modal editor. Commands only work in Normal mode. If you are in Insert mode (typing), commands like :wq are typed literally into the file instead of executing.
Step-by-Step Solution
1
Step 1: Press ESC to return to Normal mode
Press the Esc key once or twice. Your cursor changes to a block shape.
Terminal / Code
# Press the Esc key on your keyboard
If you are not sure of your mode, press Esc — it is always safe.
2
Save and Quit
Write (save) the file and quit Vim:
Terminal / Code
:wq
# Press Enter
# Shortcut: hold Shift, press Z twice
ZZ
In a git commit, this finalises your commit message.
3
Quit WITHOUT Saving (discard changes)
Exit immediately without saving any edits:
Terminal / Code
:q!
# Press Enter
# Shortcut:
ZQ
In git commit, quitting without saving aborts the commit.
4
Quit only if no changes were made
Clean exit when you only viewed the file:
Terminal / Code
:q
# Press Enter
If you made unsaved changes, Vim will warn you. Use :q! to override.
Common Mistakes to Avoid
Typing :q without pressing Esc first — the characters appear in your file.
Pressing Ctrl+C — this sends a signal but does not cleanly exit Vim.
Frequently Asked Questions
How do I stop Git from opening Vim?
Set nano as default: git config --global core.editor nano
Learn to Write Code That Doesn't Break
DoxaTech Hub's 10-month programme teaches you Git internals, Linux systems, C, Python, SQL, Docker, and React from first principles — so you spend less time fixing errors and more time shipping.
Start Learning →