How to Exit Vim Editor

In this post, we will explore all the ways and modes you can use when exiting vim. Whether saving changes or force quitting, we got you covered.

How to Exit Vim Editor

Welcome to the second article in the Vim basics series. In this series, we are covering the fundamentals of working and using Vim.

Let us go into the exciting world of Vim.

Vim Easy Exit

Once you have edited your file and saved the modified changes, you can quit Vim in a simple step.

  1. Start by pressing the ESC key to enter command mode.
  2. Next, enter a : followed by the command q.
  3. Press Return to run the command and close the editor:

Ensure that you are in Vim command mode before running the :q command.

Vim Force Quit

in some cases, you may make changes to a file and wish to discard those changes. Instead of undoing the edits, you can tell Vim to force quit and discard the modifications.

By default, if you attempt to close Vim without saving changes, you will get the E37: No Write since last change error.


This error means you have unsaved changes to the file while attempting to quit the editor.

To discard the changes, you can force quit vim by using the command :q!:


As an alternative command, you can use the key combination SHIFT + ZQ to force quit the editor.

Vim Save and Quit

If you have unsaved changes and would like to save before quitting the editor, use the Vim save and Quit command as :wq


This saves any changes to the file and closes the editor.


Vim Confirm and Quit

You can also allow VIm to prompt you for a confirmation to save any changes made to a file before quiting using the command :conf q

:conf q

This will allow you to choose whether to save or discard the changes made.

Vim Save (if necessary) and Quit

Vim also allows you to save any changes, if any, and close the editor. Instead of performing a write without any changes to save, Vim will just exit.

Use the command :x


You can also use the key combination SHIFT + ZZ. This will simply save changes (if necessary) and quit.  This option does not require you to press Return.

Vim Quit All Open Instances

If you are editing multiple files using Vim, you can close all of them at once using the command :qa or :qall


The editor may fail to close the instances where an unsaved file is encountered. To force quit all, use the command :qa! or :qall!


To save and quit all, use the command :wqa or :wqall.



And there you have it, some neat ways to quit vim editor. We hope this tutorial helped you level up in your Vim editiing skills and added a few skills to your toolbox.

We thank you for reading and stay tuned for more upcoming Vim tutorials.

If you enjoy our content, please consider buying us a coffee to support our work:

Table of Contents
Great! Next, complete checkout for full access to GeekBits.
Welcome back! You've successfully signed in.
You've successfully subscribed to GeekBits.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.