32

Given I have a group of commands such as:

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

I want to disable all the autocommands in MyGroup for a time and then re-enable it later.

Is there anything I can do with the group? Specifically, is there a way to disable the whole group at once? If not, what can I do to disable individual commands?

Looking at the help, I only see a few options:

  • augroup! will delete the whole group: I don't think this is right since I will want to re-enable it again. (But maybe there's a way to easily redefine the group again?)
  • :noautocmd will only disable the callbacks for a one-off invocation of a command. (And it disables all autocmds, not specified ones)
  • eventignore addresses the event binding, not the command: it sounds like it disables all bound commands for a given event, not just one command or a group I can specify.

How is this done?

4 Answers 4

28

From :help autocmd:

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

From :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.

So it appears :noautocmd is what you are looking for.

In what context do you want to disable an augroup?

1
  • Thanks for your answer, but I read this in the docs already. I clarified my question to (hopefully) show what I'm looking for.
    – Andrew Vit
    Jun 21, 2012 at 8:45
12

From here, it seems that this achieves it:

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

...

:autocmd! Foo BufEnter *
7

For anyone who doesn't have the original posters requirement of being able to restore the augroup, :autocmd! <augroup name> is the command to simply delete all autocmd in an augroup, e.g.:

:autocmd! MyGroup
3

If you want to temporarily disable autocmd globally for a given event, you can do:

set eventignore=CursorMoved,CursorMovedI,InsertLeave

...listing whichever events you want to temporarily ignore. This won't be limited to a specific augroup however.

To re-enable these events just reset eventignore:

set eventignore=""

Dropping this answer here in case anyone stumbles upon this question like I did but none of the other answers suffice for their situation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.