Is there a counterpart for the wall command at vim. I currently have an event handler for focus lost, so as whenever i switch to another window, vim would automatically write all of the buffers without exception (I don't know if that's the most efficient way to preserve my file changes or not). However, I was wondering if there happens to be a "plain" equivalent of wall but with the update command writing only unsaved buffers .


2 Answers 2


You are probably looking for :h :bufdo:

:[range]bufdo[!] {cmd}  Execute {cmd} in each buffer in the buffer list or if
            [range] is given only for buffers for which their
            buffer number is in the [range]. It works like doing

So you could use :bufdo update to run :update on all your buffers and only change the unsaved ones.

  • It turned out to be having a small caveat, as bufdo with update or even write command switch the current buffer to another one, and so i have keep reverting back to the buffer i was in. Is there a way to remedy this?
    – xquilt
    Commented Mar 28, 2022 at 15:51
  • Sure you could use :h getpos() before you run the command and then :h setpos() once you're done to go back where you were.
    – statox
    Commented Mar 28, 2022 at 17:19
  • I've added the following function function! Update_bufferz() let current_pos = getpos('.') silent! bufdo update call setpos('.', current_pos) endfunction then autocmd FocusLost * call Update_bufferz() but the same behavior still persists
    – xquilt
    Commented Mar 28, 2022 at 18:32
  • As i've been looking for the reason behind it for a while now, google finally landed me the right question which is exactly what i was looking for for. Still, thanks for the help!
    – xquilt
    Commented Mar 28, 2022 at 20:12

The documentation of :wall states:

Write all changed buffers. Buffers without a file name cause an error message. Buffers which are readonly are not written.

It does not state "write all buffers".

This can be verified using stat, which will list the times of last access and modification. Alternatively, turn on vim's verbose log, write it to a file (vim -V20vimlog ...) and examine it for the files vim has and has not written.

Therefore, I believe that OP can just use :wall for the stated purpose. Caveat: I have only looked at vim 8.2 as shipped with git for Windows.

  • Welcome to Vi and Vim SE. FYI, Vim 9.0 on Linux seems to work the same.
    – Friedrich
    Commented Nov 23, 2023 at 7:08
  • Given that wall default behaviors is the intended behavior, then that's indeed more straightforward. I assume all that bufdo along with update is just being more flexible!
    – xquilt
    Commented Nov 23, 2023 at 21:51

Your Answer

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

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