Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I teach vim about additional C language types for syntax highlighting?

Syntax highlighting works swimmingly beautiful with the standard types, like int, uint32_t, float and so on. However, I would like to teach vim that there are other types defined with typedef in my code, e.g.

typedef double float64_t;

How can I make vim use the same highlighting for float64_t as for the standard types? A solution with a local file (e.g. within my ~/.vimrc or .vim directory) would be preferred. Automatic parsing of typedef names not a requirement, I'm willing to add typedef names as needed.

like image 206
Jens Avatar asked Nov 22 '13 16:11

Jens


2 Answers

Here is a way to add the names as needed.

For Windows, create (replace vimfiles as appropriate)

~\vimfiles\after\syntax\c.vim

and add lines defining new syntax highlighting items. For example (from my cpp.vim),

" add nullptr as a keyword for highlighting
syn keyword Constant nullptr

To determine which group you want to add to, open a c file and type :syntax and you can look through the existing syntax groups.

like image 172
A.E. Drew Avatar answered Oct 16 '22 01:10

A.E. Drew


I also found out that we can use the match command to cover a set of typedef names described by a pattern:

match Type /\w*_t/

will highlight as a type all typedef names ending in _t (but will do so everywhere, even inside comments and string literals.)

like image 4
Jens Avatar answered Oct 16 '22 03:10

Jens