File Operations

:w, :e, :q, :wq, :x โ€” and the bangs that mean force.

Keys: :w, :e, :q, :wq, :x, :qa, :wa

Ex commands handle the file system: write, edit, quit, save-and-quit. The trailing ! means "force." :w writes; :e edits; :q quits; :wq does both; :x writes only if changed.

Ex commands (everything starting with :) are how you talk to Vim's file and buffer layer. A handful cover 95% of daily use.

Command Action
:w Write current buffer
:w {file} Write to {file} (current buffer keeps its name)
:sav {file} Write to {file} AND switch buffer to that filename
:w! Force write (read-only, etc.)
:e {file} Edit file (replace current buffer)
:e! Reload current file, discard unsaved changes
:q Close current window (or quit if last)
:q! Force quit, discard changes
:wq / :x Write and quit
:wa Write all modified buffers
:qa / :qa! Quit all / force quit all
:wqa Write all and quit

Watch

See also: Ex Ranges, Buffers