我整理了以下一堆令人敬畏的东西:
if !exists("g:AsciidocAutoSave")
let g:AsciidocAutoSave = 0
endif
fun! AsciidocRefresh()
if g:AsciidocAutoSave == 1
execute 'write'
execute 'silent !asciidoc -b html5 -a icons "%"'
endif
endf
fun! AsciidocFocusLost()
augroup asciidocFocusLost
autocmd FocusLost <buffer> call AsciidocRefresh()
augroup END
endfun
augroup asciidocFileType
autocmd FileType asciidoc :call AsciidocFocusLost()
augroup END
唯一的问题是:每次 vim 在
asciidoc
中失去焦点时,它会保存两次文件。当我放
:autocmd asciidocFileType
进入命令行,它显示:---Auto-Commands---
asciidocFileType FileType
asciidoc :call AsciidocFocusLost()
:call AsciidocFocusLost()
与
:autocmd asciidocFocusLost
相同和 AsciidocRefresh()
.为什么会出现这种重复?
最佳答案
我不能肯定地告诉你为什么你得到这些重复(多个来源?),但防止这种情况的规范方法是清除 augroup
第一的:
augroup asciidocFileType
autocmd!
autocmd FileType asciidoc :call AsciidocFocusLost()
augroup END
由于您只有一个定义,因此您也可以在一个命令中执行此操作:
augroup asciidocFileType
autocmd! FileType asciidoc :call AsciidocFocusLost()
augroup END
关于vim - autocmd 函数总是执行两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16195770/