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

> Exit Vim: press Esc, then type :q and Enter. Save and quit with :wq, quit without saving with :q!. Also why Vim traps you, and editors that quit with Ctrl+Q.

Source: https://skink.cc/articles/how-to-exit-vim/

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

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?

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

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"

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

## "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`

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

Set a different editor for git:

```sh
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:

```sh
export EDITOR=nano
export VISUAL="$EDITOR"
```

To make Skink that editor, with a lean mode for commit messages, see [Use Skink as your $EDITOR](https://skink.cc/tools/skink-as-editor/).

## 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

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

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

**Tip:**
More on quitting and closing tabs in Skink: [exit Skink](https://skink.cc/start/exit-skink/).

## Try Skink

```sh
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](https://skink.cc/compare/vim/) and [a Neovim-style editor without modes](https://skink.cc/articles/modeless-editor-for-vim-users/).
