azabiong / vim-highlighter

Highlight words and expressions
MIT License
237 stars 11 forks source link

Clear all when cursor is not on any highlight #10

Closed JoseConseco closed 2 years ago

JoseConseco commented 2 years ago

let HiErase = 'f<BS>' Deletes highlight from word under cursor. IMO It would be cool if cursor is not on any highlighted word, then it would remove all highlights (HiClear). Not big deal, but It would save me having to map extra mapping for HiClear (all)

azabiong commented 2 years ago

Hi, Thanks for your opinion! So, currently the HiErase key is being used for One Time Highlight function when the cursor is over an unhighlighted word. Are you referring to when a key is pressed in an empty space?

JoseConseco commented 2 years ago

Ah ok, I can see HiErase is doing One Time Hl - it was just hard to spot since I have lsp hover highlight, which is put on top. For users like me, it would be more helpfull for HiErase to remove all highlights, if cursor is not over highlighted word (and it seems more logical than using HiErase to add OneTimeHl) . Maybe thing like this could be done with adding callback? Something like:

fun after_hi_erase(cword_hl)
 -- user defined behavior e. g.
if no cword_hl then
  ClearAll()   -- or SetOne TimeHL()
azabiong commented 2 years ago

Oh, I see. And then, you want to use HiClear function using One Time Highlight key, correct? To do that, I think we can add an option something like this.

let HiClearUsingOneTime = 1

When this option is set, HiClear function will be called when the HiErase key is pressed over an unhighlighted word, instead of One Time Highlight. What do you think?

JoseConseco commented 2 years ago

Sounds good to me.

azabiong commented 2 years ago

Okay, I will proceed, and test, update and let you know when it's done!

azabiong commented 2 years ago

It's ready!  Please see :h HiClearUsingOneTime. I hope you like it 😄

JoseConseco commented 2 years ago

Thanks. It works great!