How to exit Vim (and editors where you don't need to ask)
To exit Vim, press Esc (to make sure you are in Normal mode), then type :q and press Enter. If Vim refuses because you have unsaved changes, type :wq to save and quit, or :q! to quit without saving.
These work the same in vi, Vim and Neovim.
All the ways to quit Vim
Section titled “All the ways to quit Vim”Press Esc first, then:
| Type | Does |
|---|---|
:q then Enter |
Quit (fails if there are unsaved changes) |
:q! then Enter |
Quit and discard changes |
:wq then Enter |
Save and quit |
:x then Enter |
Save only if changed, then quit |
ZZ |
Same as :x (no colon, no Enter) |
ZQ |
Same as :q! |
:qa / :qa! |
Quit all windows and tabs / without saving |
:wqa |
Save everything and quit |
Why can’t I exit Vim?
Section titled “Why can’t I exit Vim?”Vim is a modal editor: keys do different things in different modes. When you type, you might be in Insert mode, where :q just inserts the letters :q into your file.
Esc returns to Normal mode, where : opens the command line at the bottom. That is why the answer always starts with Esc.
Esc does nothing
Section titled “Esc does nothing”Press it twice, or press Ctrl+C. Pressing Ctrl+C in Normal mode makes Vim print a hint telling you to type :qa! to abandon changes and exit.
“E37: No write since last change”
Section titled ““E37: No write since last change””You changed the file and Vim protects it. Choose :wq to keep your changes, or :q! to drop them.
“E45: ‘readonly’ option is set”
Section titled ““E45: ‘readonly’ option is set””You opened a file you cannot write, or opened it read-only. Quit with :q!, or save anyway with :w! if you have permission.
For a root-owned file, quit and reopen it with sudoedit FILE (or sudo vim FILE).
I’m stuck in Vim after git commit
Section titled “I’m stuck in Vim after git commit”Git opened Vim to let you write the commit message. Type the message, then Esc and :wq.
To abort the commit, quit with :q! and leave the message empty. Git cancels a commit with an empty message.
Stop git from opening Vim
Section titled “Stop git from opening Vim”Set a different editor for git:
git config --global core.editor nano# or any editor you like, for examplegit config --global core.editor skinkFor every program that respects EDITOR and VISUAL (crontab, sudoedit, many CLIs), add this to your shell startup file:
export EDITOR=nanoexport VISUAL="$EDITOR"To make Skink that editor, with a lean mode for commit messages, see Use Skink as your $EDITOR.
Exiting Neovim
Section titled “Exiting Neovim”Neovim uses the same commands: Esc, then :q, :wq, :q! or ZZ.
In a Neovim terminal buffer (:terminal), first press Ctrl+\ Ctrl+N to leave terminal mode.
Editors where you don’t need to ask
Section titled “Editors where you don’t need to ask”Modeless editors do not have this problem: there is no mode where keys insert text instead of running commands. Nano shows its exit key (Ctrl+X) at the bottom of the screen. Micro and Skink quit with Ctrl+Q, like most desktop apps.
Quitting Skink
Section titled “Quitting Skink”- Ctrl+Q closes the current tab and quits when it is the last file tab.
- With unsaved changes it asks:
Save changes before quitting? (y)es / (n)o / Esc. - F4 and F10 also quit. While a debug session runs, F10 steps over instead.
- Habits from Vim work too: press Ctrl+E to open the command line (it shows the colon), then type
q,qaorwand press Enter.
Skink is also a fine core.editor for git: type the message, Ctrl+S, Ctrl+Q.
Try Skink
Section titled “Try Skink”curl -fsSL https://skink.cc/install.sh | shIt is a single binary in ~/.local/bin, no sudo. It keeps the good parts of Vim (fast, in the terminal, over SSH, keyboard-driven) without modes.