cribbing from: https://stackoverflow.com/questions/11828270/how-to-exit-the-vim-editor
Safe-quit (fails if there are unsaved changes):
:q[uit] Quit the current window. Quit Vim if this is the last window. This fails when changes have been made in current buffer.
:qa[ll]* Quit all windows and Vim, unless there are some buffers which have been changed.
Prompt-quit (prompts if there are unsaved changes)
:conf[irm] q[uit]* Quit, but give prompt when there are some buffers which have been changed.
:conf[irm] xa[ll]* Write all changed buffers and exit Vim. Bring up a prompt when some buffers cannot be written.
Write (save) changes and quit:
:wq Write the current file (even if it was not changed) and quit. Writing fails when the file is read-only or the buffer does not have a name. :wqa[ll]* for all windows.
:wq! The same, but writes even read-only files. :wqa[ll]!* for all windows.
:x[it], ZZ(with details). Write the file only if it was changed and quit, :xa[ll]* for all windows.
Discard changes and quit:
:q[uit]! ZQ* Quit without writing, also when visible buffers have changes. Does not exit when there are changed hidden buffers.
:qa[ll]!, :quita[ll][!] Quit Vim, all changes to the buffers (including hidden) are lost.
:cq as opposed to :q!
input mode
command mode <- shift ZZ (save and exit), shift ZQ (exit without saving)
ex mode <- :wq!, :q, :wx, :qa
steps:
- blank file
- vi test.txt
- :q <-
- vi test.txt
- insert and paste
- :q error!
- :q! <-
- repeat and :wq <-
- repeat and :conf q <-
- vi temp.txt
- insert and paste
- ZQ <-
- repeat and ZZ <-
- vi test.txt temp.txt
- write
- :qa <-
17: repeat and :conf q <-