: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
Outside of gvim, autoread doesn't work for me.
To get around this I use this rather ugly hack.
set autoread
augroup checktime
au!
if !has("gui_running")
"silent! necessary otherwise throws errors when using command
"line window.
autocmd BufEnter * silent! checktime
autocmd CursorHold * silent! checktime
autocmd CursorHoldI * silent! checktime
"these two _may_ slow things down. Remove if they do.
autocmd CursorMoved * silent! checktime
autocmd CursorMovedI * silent! checktime
endif
augroup END
This seems to be what the script irishjava linked to does, but that lets you toggle this for buffers. I just want it to work for everything.
Add to your vimrc
:
au CursorHold,CursorHoldI * checktime
By default, CursorHold is triggered after the cursor remains still for 4 seconds, and is configurable via updatetime.
To have autoread
trigger when changing buffers, add to your vimrc
:
au FocusGained,BufEnter * checktime
To have FocusGained
(see above) work in plain vim, inside a terminal emulator (Xterm, tmux, etc) install the plugin:
vim-tmux-focus-events
On tmux versions > 1.9, you'll need to add in .tmux.conf
:
set -g focus-events on
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
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.
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
for me it works when i use the command
:set autoread
Of course you have to save the file in the other editor before anything happens.