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.
- Start by pressing the
ESCkey to enter command mode.
- Next, enter a
:followed by the command
Returnto run the command and close the editor:
Ensure that you are in Vim command mode before running the
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
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
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
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
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
Vim Quit All Open Instances
If you are editing multiple files using Vim, you can close all of them at once using the command
The editor may fail to close the instances where an unsaved file is encountered. To force quit all, use the command
To save and quit all, use the command
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.