Ich lasse meinen Vim jedes Mal alles speichern, wenn der Fokus verloren geht.
autocmd FocusLost <your-patterns-here> silent! wall
Meine Muster sind ziemlich lang und ich benutze sie in mehreren AutocMDS, aber der Vollständigkeit halber sieht es so aus:
if exists(':keeppatterns')
let s:keeppatterns = 'keeppatterns '
else
let s:keeppatterns = ''
endif
augroup AutoSaveGroup
" :help file-pattern has some info,
" but some of it is is buried in the PATTERNS section of usr_40.txt
let s:autoPattern = "*.{c,h,[ch]pp,[acjt]s,inl,cg,cgfx,fx,py,bat,cmd,jam,vim,yml,yaml,vsprops,erb,rb,html,htm},SCons*,*vimrc"
autocmd!
execute "autocmd FocusLost" s:autoPattern "silent! wall"
execute "autocmd BufWritePre" s:autoPattern s:keeppatterns . 'call FixFormatting(expand("<afile>"))'
execute "autocmd FileChangedRO" s:autoPattern "silent !p4 edit %:p"
execute "autocmd FileChangedRO" s:autoPattern "write!"
autocmd FocusLost *.txt silent! wall
augroup END