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

前端 未结 4 716
梦谈多话
梦谈多话 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:42

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

    This method has a side-effect that, you can only open one unamed buffer. If you open the second one, it would automatically be synced to the content of the first unamed buffer.

提交回复
热议问题