# Priority highlighting

Godoy 09/18/2018. 2 answers, 58 views

In my code, something like

#include <whatever>

is highlighted: #include (which belongs to the group 'cInclude') in pink; and <whatever> (belonging to the group 'cIncluded') in red. (Edit: whatever is any word.)

Also, to highlight the word vector according to the 'Type' style (in green) I do the following:

:call matchadd('Type','\<vector\>',0)

Here, 0 sets the priority to a low value. With this, my intention is that in

#include <vector>

, <vector> is highlighted according to the group 'cIncluded', and not according to the group 'Type'.

Unexpectedly, I do not get that result. The highlight for <vector> in #include <vector> turns out to be:

< in red (as in the group 'cIncluded')

vector in green (as in the group 'Type')

> in red (as in the group 'cIncluded')

Why?

JigglyNaga 09/18/2018.

Syntax highlighting (see 'syntax') is a separate mechanism, and regardless of the chosen priority a match will always overrule syntax highlighting.

To match everywhere except certain contexts, you can use zero-width atoms:

:call matchadd('Type', '$#include <$\@<!\<vector\>')
:call matchadd('Type', '\<vector\>$>$\@!')

The first matches the complete word vector if not preceded by #include <, and the second matches when it's not followed by >. Together, these should cover all occurrences of the word other than inside #include <vector>.

Rich 09/18/2018.

I would consider using syntax matching instead of matchadd() for this:

:syntax match Type /\<vector\>/

Because you are not specifying containedin, this will not match inside the cIncluded group that already exists. See :help :syn-containedin.