I use a couple of auto commands to do highlighting of extraneous whitespace in my vim setup on InsertLeave
and BufReadPost
events. I recently started using a plugin to highlight indentation as well (https://github.com/nathanaelkane/vim-indent-guides)
The issue is that if there is an empty line with indentation, it gets highlighted by the indent-guides plugin but not by my auto commands. What I would like to do is add a custom event to the plugin so that when it is done highlighting I can set my autocommands to trigger and overwrite that highlighting in the cases where it should.
For example, this is the type of flow I would like (or at least something similar):
indent-guides plugin activates
indent-guides plugin highlights all indentation
indent-guides plugin triggers custom event signaling it is done
indent-guides plugin exits
auto command whitespace highlighter is triggered by indent-guides completion event
Here are the auto commands I am using for whitespace highlight:
autocmd InsertEnter * syn clear EOLWS | syn match EOLWS excludenl /\s\+\%#\@!$/
autocmd InsertLeave,BufReadPost * syn clear EOLWS | syn match EOLWS excludenl /\s\+$/
EDIT:
I have solved this issue another way (by editing a different plugin). This still doesn't answer this specific question, so I won't be posting that as a solution.
My solution to the problem as a plugin: https://github.com/ntpeters/vim-better-whitespace
VIM already has support for triggering both native as well as custom user events. Since your question is regarding custom events, I'd like to give a small example to demonstrate how you can do the same.
This is how you would define a custom autocmd event :
autocmd User MyCustomEvent call my_custom_function()
This is how you would trigger your defined custom autocmd event :
doautocmd User MyCustomEvent
Now you can use doautocmd
in a similar fashion to trigger both custom autocmd events like mentioned above and native vim events so depending on your use case you need to evaluate which of the two you need. The advantage of custom User autocmds are that you can rest asure no one else would trigger them whereas for native vim autocmds, they could be triggered by anybody.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With