3

More in general I'm always in doubt about what's the meaning of the {aupat} argument of autocmd for a given {event}.

From :help :autocmd I read (my emphasis)

Add {cmd} to the list of commands that Vim will execute automatically on {event} for a file matching {aupat} autocmd-patterns.

So from here it looks like {aupat} is always used maybe not to match a file name, but more in general to match a file. This kind of makes sense for events like BufWriteCmd, where {aupat} truly matching a file name, and FileType, where it matches the file type of the file.

But there are other events for which there's no such a thing as a file related to it. One example is ColorScheme, for which

The pattern is matched against the colorscheme name

reading directly from :help ColorScheme.

But not the documentation of all {event}s seem to explain what {aupat} means for them.

For instance, the word pattern doesn't even appear in :help CmdwinLeave and :help CmdwinEnter.

Hence the question: what is {aupat} matched against for {event}s CmdwinLeave and CmdwinEnter?

1
  • 1
    I believe it's matched against the type of command window entered, a single character. See: :help cmdwin-char
    – Heptite
    Sep 14, 2022 at 22:37

2 Answers 2

2

Those things are easy to test with :help <amatch>:

autocmd! CmdWinLeave * echomsg expand('<amatch>')

Where you use a wildcard to catch every possible case and echo <amatch> in the messages.

You get : when leaving q: and / when leaving q/, which lets you know what {aupat} to use in your autocommand:

autocmd! CmdWinLeave / <do something when leaving the search command-line window>
1

The documentation makes this clear I believe:

:h CmdwinLeave mentions this:

<afile> is set to a single character,
indicating the type of command-line.
|cmdwin-char|

(same for :h CmdwinEnter)

Note the |cmdwin-char|, which references another help topic, :h cmdwin-char, which finally answers your question:

The character used for the pattern indicates the type of command-line:
        :       normal Ex command
        >       debug mode command debug-mode
        /       forward search string
        ?       backward search string
        =       expression for "= expr-register
        @       string for input()
        -       text for :insert or :append
1
  • I had read that, but that doesn't say that <afile> is what {aupat} is matched against. My confusion is mostly expressed by the paragraph in my question that follows the first quote.
    – Enlico
    Sep 15, 2022 at 6:10

Your Answer

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

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