How does Vim's autoread work?

后端 未结 7 1659
[愿得一人]
[愿得一人] 2021-01-30 10:13

:h autoread says:

When a file has been detected to have been changed outside of Vim and it has not been changed inside of Vim, automatically

相关标签:
7条回答
  • 2021-01-30 11:03

    I use the following snippet which triggers autoread whenever I switch buffer or when focusing vim again:

    au FocusGained,BufEnter * :silent! !
    

    Also, it makes sense to use it in combination with the following snippet so that the files are always saved when leaving a buffer or vim, avoiding conflict situations:

    au FocusLost,WinLeave * :silent! w
    

    EDIT: If you want to speed up the write by disabling any hooks that run on save (e.g. linters), you can prefix the w command with noautocmd:

    au FocusLost,WinLeave * :silent! noautocmd w
    
    0 讨论(0)
提交回复
热议问题