views:

493

answers:

1

I have highlighted all Symbols by using tags file & highlight option.

But I could not able to highlight my local variables.

I have an idea, that is, VIM already supports autocompletion of keywords for a current file, it does autocompletion of my local variable, so, if I get a list of keywords for my current file then I will highlight those keywords by using "highlight" vim command.

But problems is, I don't know, how to get a list of keywords for a current file.

+1  A: 

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.

Al