I have XYZ highlighted in the header file where I have defined XYZ. However at the point of where it is used, XYZ is not highlighted. How would I fix this ?
I have attached two screen shots (see TH_SYN in the code) to clarify my question-
Any pointers are welcome.
It sounds like you want custom highlighting based on specific constant names etc. You can accomplish this by using
ctags
or similar to generate tags based on your constants, and then get vim to highlight the result.For more information, there are plenty of posts on ctags + vim. See, for example
Vim and Ctags tips and tricks Vim auto-generate ctags
and plenty of others.
I think it's basing the highlight on the first one on the fact that it starts with "#define". There isn't any sort of marker on the second one that vim could use to decide it needs to be highlighted. Vim doesn't do deep syntax analysis like Eclipse can do, it's just simple lexing.
I have done a very crude way of doing this for Java constants (static finals), based on the fact that all constants, are all caps with underbars. Almost no other identifiers match that criteria.
So a very simple, and very fast, but not 100% accurate is to match all caps to the same syntax group as your defines.
Edit. Adding sample
In your language syntax file just add something like:
You can do HiLink to
Constant
, or any of the defined highlight groups you like.There's no built in way to highlight defines without using a tag highlighter. If you want to just highlight defined names (rather than having the comparatively slow response of a full tag highlighter), you could modify the tag highlighter to only highlight defined names.
If you use my tag highlighter, you could modify mktypes.py (unless you're using the Windows executable version, in which case email me on the address on the website and I'll compile it for you) by changing this:
to this:
This will generate a type highlighting file that only includes defined names and it should therefore run a lot quicker. If you have too many defined names in your project then it'll still slow Vim down a bit.
To highlight only the defined names that are defined in the current file, add an autocmd that calls a Vim function after reading a file. The function should be something like:
You'll need to make sure you've highlighted DefinedName in your colourscheme, e.g.
(assuming you're using the GUI).