RRethy / vim-illuminate

illuminate.vim - (Neo)Vim plugin for automatically highlighting other uses of the word under the cursor using either LSP, Tree-sitter, or regex matching.
2.16k stars 47 forks source link

Any way to disable filetypes that match a regex? #49

Closed subnut closed 3 years ago

subnut commented 4 years ago

It's pretty annoying when comments are getting highlighted. I can disable them for each filetype manually in the vimrc, but it would be better if you allowed regex.

Then we could do something like:

let g:Illuminate_ftHighlightGroups = {
      \ '*:blacklist': ['.*[cC]omment.*']
      \ }

i.e. * => For all filetypes :blacklist => blacklist '.*[cC]omment.*' => match any highlight group containing comment or Comment in it's name

RRethy commented 4 years ago

I like the idea of *:blacklist so I added that and you can use * to specify any filetype for the whitelist. However, I didn't implement full regex matching since I don't think matching filetypes by regex is useful.

I did not add the ['.*[cC]omment.*'] since that's a non-trivial change, and you should only need Comment in that case since the highlight groups should use something along the lines of hi link goComment Comment which vim-illuminate correctly picks up as both goComment and Comment. I don't see the use-case for regex matching on the highlight group.

RRethy commented 4 years ago

This feature is also undocumented currently.

subnut commented 3 years ago

However, I didn't implement full regex matching since I don't think matching filetypes by regex is useful.

@RRethy It is useful :smiley: For example, I use vim-lsp for python files. vim-lsp uses the language server to determine which things to highlight, and is generally cleverer than this plugin. So I have added python to the blacklist. Works!

But then, I view a function definition in a floating window. vim-lsp (helpfully) adds .lsp-hover at the end of the &syntax so that plugins can use that information and act accordingly... But what happens? this plugin doesn't!

Hope you understand what I mean... my english is very poor... :sweat_smile:

RRethy commented 3 years ago

Hmmm I get what your saying, I didn't consider this scenario. I'll reopen and think about this.

subnut commented 3 years ago

Tip: For regex-matching, use a =~ b instead of a == b, in case you didn't already know :sweat_smile: If you didn't know, I suggest looking at :help expr-=~

RRethy commented 3 years ago

Thank you 😄 , I prefer using =~# though to avoid uncertainty around case matching. The main issue I have is around performance. Since filetype matching is done using a dictionary where filetypes are checked for existence, if I add regex matching, I would need to loop over the keys instead of using has_key. Since this is checked a lot, this might hurt performance which I need to investigate.

subnut commented 3 years ago

The main issue I have is around performance.

Hmm..... we could use a new variable, then. Say, g:Illuminate_ftblacklist_regex ? Then it would simply be a single string to check! :tada:

EDIT: I've tried to implement this in #55