How to determine what buffer was changed externally with gVim?
From :help FileChangedShell
:
NOTE: When this autocommand is executed, the current buffer "%" may be different from the buffer that was changed "<afile>".
You need to locate the window where the corresponding file is being edited. For that, the buffer number (in <abuf>
) is even easier:
let winNr = bufwinnr(0 + expand('<abuf>'))
execute winNr . 'wincmd w'
edit
The same applies to the buffer name; replace
let MyBn = bufname("%")
with
let MyBn = expand('<afile>')