: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
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