Vim has different and alternative solutions for different requirements. In this tutorial, we will look at different ways to quit or exit and save and exit. In this tutorial, we will use
exit for the same thing.
Exit or Quit From Vim
The most used and simple usage is just exiting or exiting from the current vim session. If there are changes after opening files this command will not work because this command does not specify action against changes. We will quit by using
Exit Vim Without Saving
We have alternative usage for exiting. As stated previous step we can not quit from vim if the file has unsaved changes. We have
:q! command which will quit without saving changes.
Write or Save and Quit From Vim
save statements for the same action. We can not exit vim sessions without saving changes. We can use
:wq command where
w will save and
q will quit. The sequence is important because they run accordingly.
OR we can use
exit command which will first save the changes and then exit.
Write and Quit Even Not Saved In Vim
Some times files we have opened and changed may be read-only. We can try to save but we will not succeed. So we can provide
:wq! command which used to try to save and quit even if the file is not saved.
Quit From All Opened Files In Vim
Vim can open multiple files at the same time. One way to close these files is one by one. Another way is closing all files with the