More on exiting vi:

  • :wq [Return] saves and exits.
  • :q [Return] exits, but only if there is nothing to save.
  • :q! [Return] exits no matter what.
  • ZZ (note that this is not a command line command, and you don't need to press [Return] or anything) also saves and exits! This information appears to fall under the category of cheat codes for vi.

I'm grateful to whoever taught me "ZZ"; I've no idea who you are, or when it was!