sponsor Vim development Vim logo Vim Book Ad

intermediate Tip #652: save all open buffers at once

 tip karma   Rating 6/12, Viewed by 862 

created:   February 6, 2004 3:50      complexity:   intermediate
author:   Andreas Berg      as of Vim:   6.0

Since i like to work with more than one buffer, i always have had the problem
that i left one of them unsaved by mistake. For this purpose i wrote this
small function which saves all open buffers (only if changes were made).
If you map the function to a key (e.g. F12), this is quite a convenient way.  

add this to your .vimrc:

function! SaveBuffers()
  if !buflisted(bufnr('%'))
    return
  end
  let myBufferNumber = bufnr('%')
  exec("bufdo update")
  exec("b".myBufferNumber)
endfunction

nmap <F12> :call SaveBuffers()<CR>

 rate this tip  Life Changing Helpful Unfulfilling 

<<Edit gnupg-encrypted files. | doxygen '///' :comments setting >>

Additional Notes

[email protected], February 6, 2004 19:01
how about :wa

I like to use it
[email protected], February 7, 2004 1:02
:-)
good hint. I didn't know it.
mosh, February 10, 2004 19:06
:xa
to save all modified buffers and exit.

:wa
will update files even if unmodified.

- Mohsin
[email protected], February 13, 2004 2:07
sorry, Mosh, that's not correct.

:wa  writes only modified buffers
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo