Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #652 - Save all open buffers at once

Created: February 6, 2004 3:50 Complexity: intermediate Author: Andreas Berg Version: 6.0 Karma: 6/12 Imported from: Tip#652

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>

Comments

how about :wa

I like to use it

loveunixnet--AT--tom.com , February 6, 2004 19:01


-)

good hint. I didn't know it.

wormdetector--AT--gmx.de , February 7, 2004 1:02


xa

to save all modified buffers and exit.

wa

will update files even if unmodified.

- Mohsin


mosh , February 10, 2004 19:06


sorry, Mosh, that's not correct.

wa writes only modified buffers

wormdetector--AT--gmx.de , February 13, 2004 2:07


Advertisement