How to exit vim?
If you are in the insert mode --> press ESC to access command mode and then just type :q! + Enter
But please note that you will exit vim without saving so you should know what you are doing!
Alternatively, you can just enter ZQ on your keyboard and exit vim without saving.
Ho to exit vim and safe?
Make sure that you are not in insert mode. If you are, press ESC to enter command mode. Then you can run :wq and voila, vim will safe your changes and exit to your terminal.
Alternatively, you can just hit ZZ and vim will save and exit as well!
More useful vim commands
Now that you know how to exit vim, here are some more commands for you.
First, hit ESC to enter the command mode and leave the insert mode. You can then type in the following commands:
- :1,10wq is going to only save the lines 1 to 10 and exit
- :x can also be used for exiting vim with saving your changes
- :ex works just as :x
- :wqa will save your changes in all tabs (in case you have more than one) and exit vim
Here's a video if you want to watch some of the above vim commands: