Editing multiple files sequentially requires efficiently loading, saving, and switching between file buffers.
A buffer is an in-memory copy of a file. Vim provides commands to load, save, and navigate between open buffers.
Basic buffer commands:
| Command | Action |
|---|---|
:e <path> | Open (edit) a file |
:w | Save current buffer |
:w <path> | Save to new file |
:saveas <path> | Save buffer as new file |
:x | Save if modified and quit |
:q | Quit (fails if unsaved) |
:q! | Quit without saving |
:qa! | Quit all, ignore changes |
:bn | Next buffer |
:bp | Previous buffer |
:q!discards unsaved changes:xonly writes if buffer is modifiedZZ=:wq(write and quit)- Buffer list persists until explicitly cleared
- Unload buffer vs delete buffer are different
- Hidden buffers:
:bnfails with unsaved changes — use:bn!or:set hidden :b#switches to alternate buffer
- Vim Splits — Each split shows a buffer
- Survival Commands — Basic save/quit
- Vim Modes — Works in Normal mode
- Macros — Can record buffer operations