How to exit from Vim/Vi is a common question asked by most of the new users who don’t have much experience with the Vim/Vi editor. Vi is a Linux command line editor and Vim is the enhanced version of Vi.
In this tutorial we are going to explain few different methods on how to exit Vim.
Exit Vim
- Press the Esc key to enter “Normal mode” in the vim editor.
- Type
:wq
to save the new changes to the file and exit. - Type
:q
to exit. You can’t just quit like this if there are any changes. - Type
:q!
to exit without saving the changes you have made.
These three methods are the basics you can use to exit from the Vim/Vi editors. It’s very simple. You can edit the file by switching into insert mode by pressing i
key and return back to normal mode by pressing esc
key.
You can see the command type in the normal mode at the bottom left corner of the terminal.
More Options to exit from Vim/Vi editor
There are more options available to play around with the Vim editor other than the above-mentioned methods. You can practice all the methods and apply as you prefer in practical usage of vim editor.
- Type
:x
in normal mode to write and exit - Type
:exit
in normal mode to write and exit (same as:x
) - Type
ZZ
in normal mode to save and exit (same as:x
) - Type ZQ in normal mode just to exit (same as
:q!
) - Type
:qa
in normal mode to quit all
Conclusion
In this short tutorial, we explained how to use different methods to exit from vim. This is one of the most googled questions by developers. Hope you can understand the simply explained tutorial and please comment on all your doubts and suggestions.