How can I make Vim autosave files when it loses focus?

Posted by Peeja on Stack Overflow See other posts from Stack Overflow or by Peeja
Published on 2011-01-09T03:44:03Z Indexed on 2011/01/09 3:54 UTC
Read the original article Hit count: 284

Filed under:
|

I'm used to my editors autosaving files when they lose focus. I recently switched to MacVim, and I can't recreate that behavior. I tried this:

autocmd BufLeave,FocusLost * wall

but if a buffer is unnamed when the window or MacVim loses focus, I get an error like the following:

Error detected while processing BufLeave Auto commands for "*":
E141: No file name for buffer 1

I'm confused, because :wall's documentation says:

Write all changed buffers.  Buffers without a file
name or which are readonly are not written.

so I'd expect it to skip unnamed buffers. Is there a better way to do this?

© Stack Overflow or respective owner

Related posts about vim

Related posts about vimrc