Save everything at once

4.3
(23)

We recently explained that with set hidden enabled, you may have unsaved buffers that aren’t visible. What if you want to save all your unsaved buffers? There are a few commands you should know:

  • :wa – Write all unsaved buffers, but keep Vim open
  • :xa or :wqa – Write all unsaved buffers, and close Vim
  • :qa – Quit Vim but stop if there are unsaved buffers
  • :qa! – Quit Vim and discard unsaved buffers

Be careful because that last one will cause you to lose work if you have some buffer hidden that has changes you haven’t written. But if you’re sure it’s safe, this can be one of the fastest ways to exit Vim.

The write-all commands of :wa, :xa, and :wqa will only write files that have unsaved changes in them. That’s different from the usual :w which writes the file no matter what. Be cognizant of this if you have compilation or other scripts that run when a file is touched.

In the screencast below, I have 2 unsaved buffers in the background. When I use :wa those files are written and Vim briefly flashes the names of the files written as it does it.

How useful was this tip?

Average rating 4.3 / 5. Vote count: 23

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

105 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts