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 :exit or 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.
This post was published (and was last revised ) by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.