1

The command :wqa does not work with new files. For example, if you create some empty files and save them with :wqa, you will not find these files after you quit vim. They are not saved at all.

The reason is, :wqa only saves changed buffers (unlike :wq).

My question is, what is the easiest way to make :wqa work like :wq on all changed and unchanged buffers?

1 Answer 1

4

:wa and :wqa will write all changed buffers; from :help :wqa:

:wqa[ll] [++opt]                                :wqa :wqall :xa :xall
:xa[ll]         Write all changed buffers and exit Vim.  If there are buffers
                without a file name, which are readonly or which cannot be
                written for another reason, Vim will not quit.

Since your new empty file isn't changed, it's not written.

:w and :wq always writes the buffer. As far as I know there isn't a shortcut to "always write all and then exit", but you can use something along the lines of:

:bufdo wq

This will run :wq on all buffers, which will always write irregardless of whether it's changed or not. Since Vim will quit if the last buffer is closed, this will also quit Vim.

3
  • The :bufdo command sees | as its argument... (See :help :bar.) You either need two separate commands (:bufdo w, followed by :q), or :execute (:exe 'bufdo w' | q).
    – filbranden
    Dec 16, 2020 at 4:05
  • 1
    I think that's not really a problem @filbranden? It just calls :q on every buffer. Actually, you can simplify this to :bufdo wq Dec 16, 2020 at 5:04
  • Ah yes true... There's the side effect that some buffers will be closed if you fail to write one in the middle of the sequence... But otherwise that should be fine.
    – filbranden
    Dec 16, 2020 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.