如何在 vim 中禁用 autocmd 或 augroup?

And*_*Vit 28 vim

鉴于我有一组命令,例如:

augroup MyGroup
  autocmd CursorMoved * silent call MyCommandOne()
augroup END
Run Code Online (Sandbox Code Playgroud)

我想暂时禁用 MyGroup 中的所有自动命令,然后再重新启用它。

我可以对小组做些什么吗?具体来说,有没有办法一次禁用整个组?如果没有,我该怎么做才能禁用单个命令?

查看帮助,我只看到几个选项:

  • augroup!将删除整个组:我认为这是不对的,因为我想再次重新启用它。(但也许有一种方法可以轻松地再次重新定义组?)
  • :noautocmd只会禁用一次性命令调用的回调。(并且它禁用所有自动命令,而不是指定的)
  • eventignore 解决事件绑定,而不是命令:听起来它禁用了给定事件的所有绑定命令,而不仅仅是我可以指定的一个命令或一组。

这是怎么做的?

rom*_*inl 25

来自:help autocmd

If you want to skip autocommands for one command, use the :noautocmd command
modifier or the 'eventignore' option.
Run Code Online (Sandbox Code Playgroud)

来自:help :noautocmd

To disable autocommands for just one command use the ":noautocmd" command
modifier.  This will set 'eventignore' to "all" for the duration of the
following command.  Example:

    :noautocmd w fname.gz

This will write the file without triggering the autocommands defined by the
gzip plugin.
Run Code Online (Sandbox Code Playgroud)

所以它似乎:noautocmd是你正在寻找的。

您想在什么情况下禁用augroup?


ivo*_*ron 11

这里看来,这实现了:

:augroup Foo
:autocmd BufEnter * :echo "hello"
:augroup END

...

:autocmd! Foo BufEnter *
Run Code Online (Sandbox Code Playgroud)


rob*_*ene 5

对于任何人谁不具有能够恢复原来的海报要求augroup:autocmd! <augroup name>是简单地删除所有的命令autocmdaugroup,例如:

:autocmd! MyGroup
Run Code Online (Sandbox Code Playgroud)