There are many commands to exit Vim, so in this article we plan to cover most of the common cases.
In order to quit Vim:
- Exit the edit mode by pressing the ESC key;
- Type-in
:q, or one of the other exit commands listed in this article, to quit; - Press the ENTER key.
#Safe-Quit
The following commands will fail if there are unsaved changes:
| Command | Description |
|---|---|
:q[uit] |
|
:qa[ll]or :quita[ll] |
|
#Save Changes and Quit
| Command | Description |
|---|---|
:wq |
|
:wqa[ll] |
|
:wq! |
|
:wqa[ll]! |
|
:x[it]or :exitor ZZ |
|
:xa[ll] |
|
#Discard Changes and Quit
| Command | Description |
|---|---|
:q[uit]!or ZQ |
|
:qa[ll]!or ::quita[ll][!] |
|
#Prompt-Quit
The following commands will prompt if there are unsaved changes:
| Command | Description |
|---|---|
:conf[irm] q[uit] |
|
:conf[irm] xa[ll] |
|
#Use Vim's Help
If you feel lost, or do not understand something, then you could refer to Vim's extensive help by doing the following:
- Press the ESC key;
- Type-in
:help; - Press the ENTER key.