Is there an autocommand that is triggered when an error occurs (a Vim error of the type E###)? A try/catch block isn't enough because I need it at a more global level.

  • It might be helpful if you can tell why you need it at global level.
    – dedowsdi
    Commented May 4, 2019 at 3:08
  • 1
    Because it's for a plugin that works in a sub-mode, and if there's an error I'd like to quit the whole mode, not just a function.
    – mg979
    Commented May 4, 2019 at 6:52
  • Sorry, couldn't help, don't have enough experience with sub-mode. Hope your comment will help others to help you.
    – dedowsdi
    Commented May 4, 2019 at 8:05
  • I provided a answer to the question. But from your comment, I assume that you should ask a different question about plugins, sub-modes and error handling.
    – Ralf
    Commented May 4, 2019 at 16:17

2 Answers 2


No, this is not really possible. It has been requested a couple of times (here, here and here and even a patch has been proposed).

But Bram disregarded this so it has never been merged.

  • Thanks. I'll probably check v:errmsg on CursorMoved, it could work for my needs.
    – mg979
    Commented May 6, 2019 at 13:12

No, there is no such autocommand event.

You might simulate something with custom autocmd events. Like:

autocmd User MyErrorEvent  call MyErrorHandler()

and somewhere in the code you could trigger that autocmd with

doautocmd User MyErrorEvent
  • Thanks. The closest I could find for now is comparing v:errmsg to an older value, so I could put that in autocommand such as CursorMoved.
    – mg979
    Commented May 5, 2019 at 13:52
  • @mg979 If you found a solution to your problem, you could post an answer and mark it as accepted: that could be useful for future readers. :)
    – statox
    Commented Jun 5, 2019 at 12:17

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.