How do I save all modified buffers at once without switching to each one?
Answer
:wall
Explanation
When working across multiple files, you often have unsaved changes in several buffers. Instead of switching to each buffer and running :w individually, :wall (write all) saves every modified buffer in a single command. This is especially useful before running tests, switching branches, or leaving Vim.
How it works
:wall— writes all modified buffers that have a filename- Skips buffers that have no filename (unnamed buffers) and read-only buffers
- If any buffer fails to write (e.g., permissions), Vim reports the error but continues saving the others
- Short form:
:wais equivalent to:wall
Example
You have 5 files open and edited 3 of them:
:ls
1 h "main.go" line 42 [+]
2 h "handler.go" line 15 [+]
3 h "config.go" line 1
4 h "test_main.go" line 8 [+]
5 a "README.md" line 1
Running :wall saves main.go, handler.go, and test_main.go in one shot.
Tips
- Use
:wallbefore:!makeor:!go testto ensure all files are saved - Map it for convenience:
nnoremap <leader>s :wall<CR> :xall(or:xa) writes all modified buffers and closes Vim:qall!discards all changes and closes — the opposite of:wall