vim-css-color
vim-css-color copied to clipboard
Disable written colors, enable only for hex
Is it possible to disable the feature for written colors, like red, blue and yellow
For my case it only makes sense to use it with hex.
So what is your case?
Whether colour keywords are highlighted (and which ones) already varies: it’s based on the filetype.
I would really appreciate this as well.
I use a lot of CSS utility classes in HTML-like documents (e.g. class="text-red-700 bg-gray-200) and having the color names highlighted in that situation can be distracting, especially when the colours don't match the shade at all (and obviously couldn't).
I imagine it would be difficult to disable the colouring inside class attributes, while keeping it in <style> tags and style attributes, so being able to just disable the written color highlighting completely would be very helpful.
For me, the utility of this plugin is in showing what human-unfriendly hex and RGB colours look like. Written color names don't suffer the same problem so I'd prefer be able to disable them completely rather than have the utility classes highlighted.
Thanks for the feedback. That doesn’t sound like a use case to me, though? To me that’s just a bug. The plugin is syntax-sensitive specifically to keep from highlighting things inappropriately; in this case, only the values of style attributes should be getting highlighted, not just any and all attribute values. Would you still feel the need to be able to turn off keywords in specific filetypes if that was the case?
I appreciate the response!
Yeah I guess technically it probably is a bug for that specific example. I just assumed it was a Vim quirk or limitation and that making it behave as desired would involve some error-prone regex or something. If it were able to only highlight written colors in style attributes and <style> tags (i.e. in CSS) that would be amazing.
There are a handful of other situations that are more of a gray area though, such as in JavaScript where it seems to highlight the color names anywhere they appear as a string:

Or a more contrived example:

It's not a big deal, but I still feel like if given the option I would prefer to just disable the written color highlighting rather than have these various occurrences of it being a bit weird - at least for filetypes where it might be too ambiguous.
A workaround is to clone this repository, then go to :
~/syntax/colornames/extended.vim
And delete the content of the file. Not very elegant, but it works.
I've found it very difficult to adapt vim-css-color to avoid inappropriate uses of color names. My example is:
p.tan { width: calc(100px * tan(45deg)); }
While the class name isn't colored, the tangent function call is.
I saw that the code attempts to avoid white-space from getting colored with a similar negative lookahead:
syn match BGffffff "\c\<white\(-\)\@!\>" contained containedin=@colorableGroup
This appears to do what we want, to avoid coloring white when it is followed by a dash, but if you replace it with a keyword variant that lacks the negative lookahead, there is no behavior change (white-space is still uncolored, as is tan-space). This explains why I cannot get \c\<tan\([(]\)\@!\> to work, though it doesn't explain why I can't get even \<tan\> to color anything.
Another attempt was to change the end of autoload/css_color.vim's s:create_syn_match() to enhance the pattern end from '\> to \>\%([(-\)\@! (I even tried it outside the escape() just in case).
The only solution I could get was to expand the keyword list to include open parenthesis, thus making vim try to match tan(45deg instead of tan. I'm not sure of the consequences of that change, so I'll follow the vim help advice and avoid it. (See adamhotep@5dda713.)
Coming back to this particular issue: At least in CSS files, iskeyword containing a dash means brand-red will never match a keyword of red. Also in CSS files, cssStringQ cannot contain color keywords, so it shouldn't match anything. I can't reproduce this issue in HTML or CSS; what syntax does this affect?