how to highlight variables of c/c++ files in vim

回眸只為那壹抹淺笑 提交于 2019-12-11 02:47:16

问题


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?


回答1:


In general, you need to do two things:

  1. Generate tags using ctags;
  2. 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.




回答2:


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



来源:https://stackoverflow.com/questions/8635659/how-to-highlight-variables-of-c-c-files-in-vim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!