如何在vim中禁用autocmd或augroup?


25

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

augroup MyGroup
  autocmd CursorMoved * silent call MyCommandOne()
augroup END

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

我可以和这个小组做些什么吗?具体来说,有没有一种方法可以立即禁用整个组?如果没有,我该怎么做才能禁用单个命令?

查看帮助,我只看到一些选择:

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

怎么做?

Answers:


20

来自:help autocmd

If you want to skip autocommands for one command, use the :noautocmd command
modifier or the 'eventignore' option.

来自: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.

看来:noautocmd这就是您要寻找的。

您要在什么情况下禁用augroup


感谢您的回答,但是我已经在文档中阅读了此内容。我澄清了我的问题,以(希望)展示我在寻找什么。
安德鲁·维特

8

这里开始,看来可以实现:

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

...

:autocmd! Foo BufEnter *

1

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

:autocmd! MyGroup
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.