Skip to content
/
Try

How to exit Vim (and editors where you don't need to ask)

Ctrl+Q quits. Unsaved work? It asks first.

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.

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

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.

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.

You changed the file and Vim protects it. Choose :wq to keep your changes, or :q! to drop them.

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).

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.

Set a different editor for git:

Terminal window
git config --global core.editor nano
# or any editor you like, for example
git config --global core.editor skink

For every program that respects EDITOR and VISUAL (crontab, sudoedit, many CLIs), add this to your shell startup file:

Terminal window
export EDITOR=nano
export VISUAL="$EDITOR"

To make Skink that editor, with a lean mode for commit messages, see Use Skink as your $EDITOR.

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.

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.

  • 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, qa or w and press Enter.

Skink is also a fine core.editor for git: type the message, Ctrl+S, Ctrl+Q.

Terminal window
curl -fsSL https://skink.cc/install.sh | sh

It 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.

See Skink vs Vim and a Neovim-style editor without modes.