Is there any way to add syntax coloring to new types defined with typedef
statements in C?
typedef struct {
int a,b;
} MyStruct;
MyStruct *InitMyStruct(MyStruct *struct, int a, int b);
^ ^ ^ ^ ^
+---------+-----------+ +------+
Same Color Correct type color
If it's not possible natively (I guess so), are there any plugins to make this visual clue work?
I found the exact solution to my question in Vim's help, and I'm posting it here in case someone needs this in the future. It's exactly what I want: a way to read the code and highlight it accordingly.
[...]
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With