How does Vim's autoread work?

Solution 1:

Autoread does not reload file unless you do something like run external command (like !ls or !sh etc). vim does not do checks periodically. You can reload file manually using :e.

More details in this thread: Click here

Solution 2:

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

Solution 3:

As per my posting on superuser.com

Autoread just doesn't work. Use the following.

http://vim.wikia.com/wiki/Have_Vim_check_automatically_if_the_file_has_changed_externally

I got the best results by calling the setup function directly, like so.

let autoreadargs={'autoread':1} 
execute WatchForChanges("*",autoreadargs) 

The reason for this, is that I want to run a ipython/screen/vim setup.

Solution 4:

A bit late to the party, but vim nowadays has timers, and you can do:

if ! exists("g:CheckUpdateStarted")
    let g:CheckUpdateStarted=1
    call timer_start(1,'CheckUpdate')
endif
function! CheckUpdate(timer)
    silent! checktime
    call timer_start(1000,'CheckUpdate')
endfunction