You can match only those identifiers ending with _t
(not those that contain _t
partway through like foo_table
) by using negative lookahead.
Place in ~/.vim/after/syntax/c.vim
:
syn match cType "\h\w*_t\w\@!"
\h
(head of word) means the same as [A-Za-z_]
i.e. it will match any character that can start an identifier in C. \w*
(word) means the same as [0-9A-Za-z_]*
i.e. it will match any characters that can continue an identifier in C. _t
will literally match those two characters. \w\@!
is negative lookahead: it will match as long as \w
does not match i.e. it will match as long as the _t
is not followed by an alphanumeric character or an underscore.
Note: This is subtly different to \h\w*_t\W
which will match a foobar_t
type followed by something other than [0-9A-Za-z_]
, which means it won't match at the end of the line or end of the file. That pattern will also match and highlight as a keyword that following character, which is definitely not what you want.