
Estou usando o seguinte comando automático do Vim em meu .gvimrc
arquivo:
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
com a intenção de substituir o comportamento padrão do gVim quando um arquivo é alterado externamente (vejaessa questão). Porém, se múltiplas janelas forem abertas, mostrando vários buffers, o edit
comando funciona na última janela ativa, e não na janela que contém o buffer que foi alterado.
Como posso determinar qual buffer causou o FileChangedShell
evento e aplicar o edit
comando a esse buffer?
Responder1
De :help FileChangedShell
:
NOTE: When this autocommand is executed, the current buffer "%" may be different from the buffer that was changed "<afile>".
Você precisa localizar a janela onde o arquivo correspondente está sendo editado. Para isso, o número do buffer (in <abuf>
) é ainda mais fácil:
let winNr = bufwinnr(0 + expand('<abuf>'))
execute winNr . 'wincmd w'
edit
O mesmo se aplica ao nome do buffer; substituir
let MyBn = bufname("%")
com
let MyBn = expand('<afile>')
Responder2
Obrigado à resposta do @IngoKarkat. Encontrei uma solução alternativa. Substitua o if
bloco na função por:
if MyTest == 2
let v:fcs_choice = "reload"
else
let v:fcs_choice = ""
endif
Isso parece funcionar.