I want to highlight variables in a C/C++ file .
such as:
int num;// Highlighted num
char str;// Highlighted str
struct data
{
int year;
int month;
};
struct data *p,time;// Highlighted p time
..........
How to highlight variables as given above (num ,str, p,time.....)
I know we can modify syntax\c.vim to reach that,but how to write the syntax?
Is there any other solution?
In general, you need to do two things:
- Generate tags using
ctags
;
- Generate syntax file using resulting tags file.
Now some details.
There are plugins to help you. Firstly, plugin Indexer automatically generates tags for a whole project and keeps tags up-to-date. (i'm author of this plugin, so, if you have any problems using it, feel free to ask me)
And secondly, there's plugin TagHighlight to extra highlights variables, enums, typedefs, etc.
If you mean how to turn on syntax highligting, then you need to:
:syntax on
If it does not work, determine filetype first:
:set filetype?
Should print "cpp". If not, set it first:
:set filetype=cpp