Frequently Asked Question
What do :w, :q, :wq, and :q! actually do?
All four are ex commands, entered by pressing : in normal mode, which drops you
into the command-line at the bottom of the screen. :w writes the current buffer
to disk, using the filename Vim already knows about. You can pass a different
filename (:w other.txt) to save a copy, or a range (:5,10w extract.txt) to
write only those lines.
:q quits the current window. If the buffer has unsaved changes, Vim refuses and
prints E37: No write since last change. :wq is the common combination, write
then quit, and :x is almost the same except it only writes if changes were made
(slightly nicer for file modification timestamps). The shortcut ZZ in normal
mode is identical to :x.
:q! is the force-quit: discard any unsaved changes, leave immediately. The !
after almost any Vim command means "I really mean it" and overrides safety checks.
Use :wq! to force a write even when the file is read-only (Vim will use chmod
tricks if it can), and :qa! to quit all open windows discarding changes
everywhere.