
Estoy usando el siguiente comando automático de Vim en mi .gvimrc
archivo:
augroup MyAuGroup
autocmd MyAuGroup FileChangedShell * call FileChanedEvent_BuffUpdate()
augroup END
function FileChanedEvent_BuffUpdate()
let MyBn = bufname("%")
let MyStr = "Warning: File \"".MyBn."\" has changed since editing started\nSee \":help W11\" for more info."
let MyTest = confirm(MyStr, "&OK\n&Load File", 2, "W")
if MyTest == 2
edit
else
endif
endfunction
con la intención de reemplazar el comportamiento predeterminado de gVim cuando un archivo se cambia externamente (veresta pregunta). Sin embargo, si se abren varias ventanas que muestran varios búfer, el edit
comando funciona en la última ventana activa y no en la ventana que contiene el búfer que se cambió.
¿Cómo puedo determinar qué búfer causó el FileChangedShell
evento y aplicar el edit
comando a ese búfer?
Respuesta1
De :help FileChangedShell
:
NOTE: When this autocommand is executed, the current buffer "%" may be different from the buffer that was changed "<afile>".
Debe ubicar la ventana donde se está editando el archivo correspondiente. Para eso, el número de buffer (en <abuf>
) es aún más fácil:
let winNr = bufwinnr(0 + expand('<abuf>'))
execute winNr . 'wincmd w'
edit
Lo mismo se aplica al nombre del búfer; reemplazar
let MyBn = bufname("%")
con
let MyBn = expand('<afile>')
Respuesta2
Gracias a la respuesta de @IngoKarkat. Encontré una solución alternativa. Reemplace el if
bloque en la función con:
if MyTest == 2
let v:fcs_choice = "reload"
else
let v:fcs_choice = ""
endif
Esto parece funcionar.