Coloring certain types as types

Is there a way to add syntax coloring to new types defined using typedef statements in C?

 typedef struct { int a,b; } MyStruct; MyStruct *InitMyStruct(MyStruct *struct, int a, int b); ^ ^ ^ ^ ^ +---------+-----------+ +------+ Same Color Correct type color 

If this is not possible initially (I think so), are there any plugins to make this visual hint?

+6
source share
1 answer

I found the exact solution to my question in Vim help, and I am posting it here if someone needs it in the future. This is exactly what I want: a way to read the code and highlight it accordingly.

syntax.txt

Section 15: Highlighting Tags

 [...] Only highlighting typedefs, unions and structs can be done too. For this you must use Exuberant ctags (found at http://ctags.sf.net). Put these lines in your Makefile: # Make a highlight file for types. Requires Exuberant ctags and awk types: types.vim types.vim: *.[ch] ctags --c-kinds=gstu -o- *.[ch] |\ awk 'BEGIN{printf("syntax keyword Type\t")}\ {printf("%s ", $$1)}END{print ""}' > $@ And put these lines in your .vimrc: > " load the types.vim highlighting file, if it exists autocmd BufRead,BufNewFile *.[ch] let fname = expand('<afile>:p:h') . '/types.vim' autocmd BufRead,BufNewFile *.[ch] if filereadable(fname) autocmd BufRead,BufNewFile *.[ch] exe 'so ' . fname autocmd BufRead,BufNewFile *.[ch] endif 
+9
source

Source: https://habr.com/ru/post/886934/


All Articles