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

前端 未结 4 711
梦谈多话
梦谈多话 2020-12-25 11:02

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 Bu         


        
4条回答
  •  庸人自扰
    2020-12-25 11:44

    I suspect when docs for wall say "without a file name" they may be referring to buffers with buftype=nofile . One way to get what you want would be to have the autocmd have bufdo call a simple function. E.g., some untested code to give the idea:

    autocmd BufLeave,FocusLost * bufdo! call WriteFile()
    
    function WriteFile()
       if (&buftype=="") && (expand("%:r") > "") && (&readonly==0)
          write
       endif
    endfunction
    

    I think the standard way of getting something like this automatic saving of buffers would be to set the autosave option in Vim.

提交回复
热议问题