From :h autocmd-events:

You can specify a comma-separated list of event names.  No white space can be
used in this list.  The command applies to all the events in the list.

From :h {pat}:

The {pat} argument can be a comma separated list.  This works as if the
command was given with each pattern separately.  Thus this command:
    :autocmd BufRead *.txt,*.info set et
Is equivalent to:
    :autocmd BufRead *.txt set et
    :autocmd BufRead *.info set et

However, it seems that not all events match {pat} against the file name: I've just discovered, for instance, the existence of OptionSet, which matches {pat} against an option name.

I'm therefore curious to know how multiple events and multiple patters in a single autocmd interact. In other words, I wondering if I can use a single autocmd instead of two in the following group:

augroup DiffMappings
  autocmd BufEnter * :call SetDiffMappings()
  autocmd OptionSet diff :call SetDiffMappings()
augroup end

1 Answer 1


The answer is very obvious indeed: it works as dumb Cartesian product. In fact, "commas" are there only to save a few keystrokes.

What it means in practice: autocmd BufEnter,OptionSet *,diff : is syntactically valid nonsense.

  • I was hoping in a component-wise product. Thanks :)
    – Enlico
    Commented Jan 30, 2021 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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