I have a log library that has a autocmd log User hook, to show saved log or set it to a dedicated scratch buffer or etc.

It works quite well, but there is slight nuisance. When inspection/debug done, I clear the hook by au! log User. But then No matching autocommands: log User will show at cmdline constantly. Since the log#log function invoke doa log User.

Is there a way to suppress the No matching autocommands: log User message when doa log User but no log User autocmd being set.
Or is there a function to check existence of a specified autocmd, if no one, then do not doa (to avoid No matching autocommands noise).

Failed attempts:

  • use sil doa, then hook that just echoes will never work. Unacceptable.
  • 1
    See :h exists()
    – Matt
    Commented Jan 19, 2023 at 13:51

1 Answer 1


Thx to Matt's comment. Found the answer in :h exists.

the relevant part is.

    #event      autocommand defined for this event
    #event#pattern  autocommand defined for this event and
                    pattern (the pattern is taken
                    literally and compared to the
                    autocommand patterns character by
    #group      autocommand group exists
    #group#event    autocommand defined for this group and
                    autocommand defined for this group,
                    event and pattern.
    ##event     autocommand for this event is

thus answer for my case is

    if exists('#log#User')
        doa log User

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.