0

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.

4
  • It might be helpful if you can tell why you need it at global level.
    – dedowsdi
    May 4 '19 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
    May 4 '19 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
    May 4 '19 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
    May 4 '19 at 16:17
1

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
2
  • 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
    May 5 '19 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
    Jun 5 '19 at 12:17
0

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.

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

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.