0

I have this function that I rarely run and it uses matchaddpos. This function highlights at a set position so if I edit text, the same spot is highlighted even though the contents have shifted. I figure the best way to solve this is to create an autocmd like this:

augroup headwords
    autocmd!
    autocmd InsertEnter * call clearmatches()
augroup end

That works fine, but it seems unnecessary to have that run every time I enter insert mode. How could I make this "self destructing". Where if this autocmd runs one, it no longer runs on future InsertEnter's?

2

You can simply use autocmd! headwords. For example,

augroup headwords
    autocmd!
    autocmd InsertEnter * call clearmatches() | autocmd! headwords
augroup end

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.