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:

  1. blank file
  2. vi test.txt
  3. :q <-
  4. vi test.txt
  5. insert and paste
  6. :q error!
  7. :q! <-
  8. repeat and :wq <-
  9. repeat and :conf q <-
  10. vi temp.txt
  11. insert and paste
  12. ZQ <-
  13. repeat and ZZ <-
  14. vi test.txt temp.txt
  15. write
  16. :qa <-
    17: repeat and :conf q <-