How To Exit From Vim?
Vim have different and alternative solutions for different requirements. In this tutorial we will look different ways to quit or exit and save and exit. In this tutorial we will use
exit for the same thing.
Exit or Quit
The most used and simple usage is just exiting or exiting from the current vim session. If there is changes after opening file this command will not work because this command do not specifies action against changes. We will quit by using
Exit Without Saving
We have alternative usage for exiting. As stated previous step we can not quit from vim if file has unsaved changes. We have
:q! command which will quit without saving changes.
Write or Save and Quit
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
Some times files we have opened and changed may be read only. We can try to save but we will not succeeded. So we can provide
:wq! command which used try to save and quit even if file is not saved.
Vim can open multiple file at the same time. One way to close these files is one by one. Another way is closing all files with the