How to Exit Vim
Learn a few patterns first:
General mode: Press the ESC key
Command-line mode: First cut to normal mode, then press SHIFT key and then enter ":"
Insert mode: Press A or I in general mode
Seven Ways to Exit
1, command line mode, enter "Q" after the return. This is a normal exit, only if the file has not been modified or the modification has been saved under the circumstances can be successfully exited, otherwise you will be prompted to change has not been saved and cannot exit.
2, command line mode, enter "q!" Back to enter. This is a forced exit and when a file has been modified and has not been saved, forcing the exit discards the modification.
3, command line mode, enter "Wq" after the return. This belongs to the first save and exit, only if the open file can be written and have edit permission to exit successfully, otherwise you will be prompted insufficient permissions or file read-only warning.
4, command line mode, enter "wq!" Back to enter. This is mandatory to save and exit, only if you have edit permission on the open file can exit successfully, otherwise you will be prompted insufficient permissions and other warnings. Read-only files with access rights can be successfully saved and exited even if they have been modified.
6, the general mode, enter "ZZ". This belongs to the first save after exiting, with "Wq".
7, General mode, enter "ZQ". This belongs to the forced exit, with "q!".