How can vim tell me which buffer is changed on disk among multiple buffers?
related to this thread, @b-layer helped me

my current vimrc code:

set autoread
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | checktime | endif
autocmd FileChangedShellPost *
  \ echohl WarningMsg | echo "File " . expand('<afile>') . " changed on disk. Buffer reloaded." | echohl None

If i have multiple files let's say 4 tabs open in vim and one file is changed,
it will show File A.cpp changed on disk. Buffer reloaded.

But i need to add a feature which will work like this
suppose, i have 4 files (opened as tabs in vim)


If two files are changed outside vim, it will show File A.cpp C.cpp changed on disk. Buffer reloaded.

  • The FileChangedShellPost is triggered for each buffer so maybe instead of echoing the message directly you could add the filename to a global variable and then have a function which would be called periodically with a trigger. The function would check the content of the variable, create the message and echo it and empty the global variable.
    – statox
    Jul 15 at 12:37
  • I don't know much vimscript.. could you please make that function for me?
    – Mega Bang
    Jul 15 at 12:45
  • 1
    Right now I can't but that would be a good learning opportunity: Try to make your own function and if there is something in particular you have an issue with post it here :) There are a bunch of chapters here which should give you all the info you need to write your code
    – statox
    Jul 15 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.