If you’re a Linux user, chances are you’ve had to use Vim. Vim is a highly configurable text editor that’s very efficient – when you know how to use it. For beginners, though, it can feel a bit overwhelming, especially when you’re trying to do something as simple as exiting the program! Not to worry, though. We’re here to help.
Exiting Vim
When you find yourself in Vim and want to exit, use the following command:
The :q command will quit the currently open file in Vim. If you’ve made changes to the file, Vim will not allow you to exit without either saving your changes or explicitly discarding them.
Quitting Without Saving
If you want to quit Vim and discard any changes, use this command:
The :q! command tells Vim to quit without saving changes.
Saving and Quitting
If you wish to save your changes and then quit Vim, use this command:
The :wq command writes the changes (save) and then quit.
Summary
Exiting Vim is not as intuitive as other text editors, but once you get the hang of it, it becomes second nature. Remember, use :q to quit, :q! to quit without saving, and :wq to save and quit.
Happy Vim-ing!