Priority highlighting

Godoy 09/18/2018. 2 answers, 58 views
syntax-highlighting highlight

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')


2 Answers

JigglyNaga 09/18/2018.

From help matchadd:

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. - Download Hi-Res Songs

1 Alan Walker

On My Way flac

Alan Walker. 2019. Writer: Alan Walker;Sabrina Carpenter;Farruko.

Here With Me flac

CHVRCHES. 2019. Writer: Steve Mac;Martin Doherty;Marshmello;Lauren Mayberry;Iain Cook.
3 5 Seconds Of Summer

Who Do You Love flac

5 Seconds Of Summer. 2019. Writer: Andrew Taggart;Talay Riley;Oak;Sean Douglas;Luke Hemmings;Calum Hood;Ashton Irwin;Michael Clifford;Trevorious;Zaire Koalo.
4 Bonn

No Sleep flac

Bonn. 2019. Writer: Albin Nedler;Bonn;Martin Garrix.
5 Avril Lavigne

Crush flac

Avril Lavigne. 2019. Writer: Johan Carlsson;Avril Lavigne;Zane Carney.
6 Katy Perry

365 flac

Katy Perry. 2019. Writer: Zedd;Katy Perry;Caroline Ailin;Corey Sanders;Daniel Davidsen;Cutfather;Peter Wallevik.
7 Alan Walker

Are You Lonely flac

Alan Walker. 2019.
8 Jonas Brothers

Sucker flac

Jonas Brothers. 2019. Writer: Kevin Jonas;Joe Jonas;Nick Jonas;Ryan Tedder;Louis Bell;Frank Dukes.
9 Brooks

Better When You're Gone flac

Brooks. 2019. Writer: David Guetta;Emma Lov Block;Ido Zmishlany;Jackson Foote;Jeremy Dussolliet;Brooks.
10 Dido

Hurricanes flac

Dido. 2019. Writer: Dido;Rick Nowels;Rollo Armstrong.

Happy flac

DEAMN. 2019.
12 Ariana Grande

Bloodline flac

Ariana Grande. 2019. Writer: ILYA;Max Martin;Savan Kotecha;Ariana Grande.

Rise flac

IZ*ONE. 2019.
14 Avril Lavigne

Dumb Blonde flac

Avril Lavigne. 2019. Writer: Mitch Allan;Bonnie McKee;Nicki Minaj;Avril Lavigne.
15 Little Big Town

Don't Threaten Me With A Good Time flac

Little Big Town. 2019. Writer: Thomas Rhett;Karen Fairchild;The Stereotypes;Jesse Frasure;Ashley Gorley.
16 Ariana Grande

Make Up flac

Ariana Grande. 2019. Writer: Brian Malik Baptiste;Tayla Parx;TBHits;Victoria Monét;Ariana Grande.
17 Dzeko

Halfway There flac

Dzeko. 2019.
18 Ariana Grande

Imagine flac

Ariana Grande. 2019. Writer: JProof;Priscilla Renea;Happy Perez;Andrew "Pop" Wansel;Ariana Grande.
19 Ariana Grande

NASA flac

Ariana Grande. 2019. Writer: Ariana Grande;Scootie;Tayla Parx;TBHits;Victoria Monét.
20 Ariana Grande

Thank U, Next flac

Ariana Grande. 2019. Writer: Crazy Mike;Scootie;Victoria Monét;Tayla Parx;TBHits;Ariana Grande.

Related questions

Hot questions


Popular Tags