You can highlight recognised names using the tags file as long as the tags file is generated with the --c-kinds=+l
to ensure that it includes local variables. However, there is currently no realistic way to identify the scope of those variables (ctags does not provide much information), therefore Vim will not distinguish between variables in one function and another:
void main(void)
{
int MyVariable; // Highlighted
}
int MyFunction(void)
{
int MyFunctionVariable; // Highlighted
MyVariable = 1; // Syntax error, but still highlighted
}
It could be done by parsing the C file in a little more detail and creating syntax regions for each function, but it is far from easy (and it would be incompatible with plugins like rainbow.vim as Vim doesn't support overlapping regions).
On a related note, you may also be interested in my tag highlighting plugin available here. It will highlight local variables (if b:TypesFileIncludeLocals
is set to 1
in the buffer open when running :UpdateTypesFile
), but it doesn't deal with the scope of local variables. It does, however offer a lot more highlighting colour variations than the highlighting suggested in :help tag-highlight
. Note that your colour scheme will have to have highlights defined for lots of extra groups (e.g. GlobalVariable
, LocalVariable
, DefinedName
etc) to take full advantage of it.