5

I know that syn match can work with the regular expression to do some custom highlight settings.

I'm thinking if it can work dynamically.

For example, I'm doing a c++ project and I want to highlight all class/struct names. It's not hard to highlight these names while defining, I can do this with the help of syn match as below:

hi hiCppCustomClassName guifg=NONE guibg=NONE guisp=NONE gui=bold ctermfg=lightgreen ctermbg=NONE cterm=bold
syn match cppCustomClassName "\(^class\s*\)\@<=\w\+"
syn match cppCustomStructName "\(^struct\s*\)\@<=\w\+"
hi def link cppCustomClassName hiCppCustomClassName
hi def link cppCustomStructName hiCppCustomClassName

Basically, I match all words following the key word class and struct and highlight them.

However, if I define an object with some class, it won't be highlighted, which means that:

class Test{}; // Test is highlighted
Test t;       // Test it not highlighted

As there are many cases, such as sizeof(Test), (Test)obj, the syn match with regular expression can not cover all of them, now I'm thinking if there is some dynamic mechanism so that I can find all class/struct names, put all of them into an array, loop this array and highlight all of them while coding.

BTW, I know there are some other ways to get a perfect highlight, for example, https://github.com/jeaye/color_coded, but these are kind of too heavy, for now I only want to get some simple, light way.

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.