File Operations
:w, :e, :q, :wq, :x โ and the bangs that mean force.
Ex commands handle the file system: write, edit, quit, save-and-quit. The trailing ! means "force.":wwrites;:eedits;:qquits;:wqdoes both;:xwrites only if changed.
You've known :w, :q, and :wq since Survival โ they were the bare minimum for opening, saving, and quitting. This chapter is the full picture: the variants you haven't seen yet (:sav, :wa, :wqa, :e!), and the underlying model. 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 |