Reputation: 23134
From vimdoc:
:checkt[ime] Check if any buffers were changed outside of Vim. This checks and warns you if you would end up with two versions of a file. If this is called from an autocommand, a ":global" command or is not typed the actual check is postponed until a moment the side effects (reloading the file) would be harmless.
How can I use it from an autocmd without delay?
I somtimes use vim and an IDE to edit the same file, and I want to changes in one of them to be loaded into the other automatically.
Here is a possible solution:
autocmd CursorHold * checktime
function! Timer()
call feedkeys("f\e")
" K_IGNORE keycode does not work after version 7.2.025)
" there are numerous other keysequences that you can use
endfunction
But since checktime will be delayed, the effect may not be satisfactory.
Upvotes: 0
Views: 993
Reputation: 23134
I ended up doing this:
autocmd CursorHold * call Timer()
function! Timer()
checktime
call feedkeys("f\e")
endfunction
It works quite well.
Upvotes: 1
Reputation: 172658
As the quoted documentation explains, you can't, and for good reason (the reload might trigger other autocmds, the change might confuse following commands).
To work around this, you have to leave the current :autocmd
, and re-trigger your code somehow. One idea is an :autocmd BufRead
, which will fire if the buffer is actually reloaded. If you need to always retrigger, an :autocmd CursorHold
(maybe with a temporarily reduced 'updatetime'
) can be used, or call feedkeys(":call Stage2()\<CR>")
might be worth a try.
Upvotes: 1