feat(autoread): use filewatchers for OS-driven change detection #37971

Problem:
The 'autoread' option only checks for file changes reactively — on
FocusGained, :checktime, CmdlineEnter, etc. — by polling timestamps.
External changes are not detected until the user interacts with Neovim.

Solution:
Add a core module (runtime/lua/nvim/autoread.lua) enabled from
runtime/plugin/autoread.lua that watches each buffer's file using
vim._watch.watch() (libuv fs_event). On change detection it calls
:checktime, which invokes the existing buf_check_timestamp() logic
for reload/prompt handling. Watchers are managed via autocmds tied
to buffer lifecycle events and respect the 'autoread' option (global
and buffer-local).
This commit is contained in:
Oleksandr Chekhovskyi
2026-06-13 01:25:15 +03:00
committed by GitHub
parent c622b454b5
commit 400f247397
8 changed files with 411 additions and 3 deletions

View File

@@ -305,7 +305,8 @@ local options = {
it has not been changed inside of Vim, automatically read it again.
When the file has been deleted this is not done, so you have the text
from before it was deleted. When it appears again then it is read.
|timestamp|
Nvim uses file system watchers to detect changes in real-time for all
loaded buffers; see |timestamp| for details.
If this option has a local value, use this command to switch back to
using the global value: >vim
set autoread<