:wq (write & quit)
What is :wq (write & quit)?
:wq (write & quit): Vim: save the file and close the editor. The legendary "how do I exit Vim" answer. :wq is the Vim command to write the file and quit. You press Escape to make sure you are in normal mode, type :wq, and press Enter. :q! quits without saving, and :x saves only when something changed.
Frequently asked questions about :wq (write & quit)
How is :wq (write & quit) used in practice?
Most developers meet Vim by accident. Git opens it for a commit message or during a rebase, and suddenly the keyboard does not behave as expected. Knowing these three commands gets you out safely.
What should you keep in mind with :wq (write & quit)?
If you would rather use another editor, tell Git so. git config --global core.editor "code --wait" makes Git open VS Code and wait until you close the tab. Setting the EDITOR variable in your shell does the same for most other tools. That said, basic Vim is worth an hour of practice, because it is installed on nearly every server you will ever log into.
At a glance
| Category | Keyboard shortcuts |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |