Highlight region between XML tags

46 views
Skip to first unread message

Silas Silva

unread,
Jan 16, 2012, 2:51:59 PM1/16/12
to vim...@googlegroups.com
Hi all.

I'm facing small problems regarding highlight of regions between XML
tags. docbk.vim (that includes xml.vim) syntax file works almost fine
with DocBook tags, like those:

<title>bla</title>
<emphasis>foo</emphasis>

But, those only work when the highlighted text and the tags (that define
the region) are in the same line. So, the following doesn't work:

<title>
bla
</title>

<emphasis>
foo
</emphasis>

So, since I would like to highlight text between for tag <foo>, I wrote
my own rules:

syn region myFoo start='<foo>' end='</foo>' skipwhite keepend
hi! def link myFoo Constant

These works for text between <foo> and </foo>, but it also highlights
the tags. I thought using offsets (ms=s+1 and me=s-1), but
fantastically it doesn't work (it colors the whole region, including the
tags or none of it). After commenting some code in Vim's xml.vim, I
discovered that commenting tag definition at line 196 made it work.

Is it possible, in syntax definitions, to make a string not match a
rule, even if it would match according to regular expressions previously
defined?

Thanks in advance.

--
Silas Silva

Ben Fritz

unread,
Jan 17, 2012, 10:55:01 AM1/17/12
to vim_dev
You'll need to play with the contains keyword of your group to include
the normal highlighting rules, or the matchgroup keyword. As explained
at :help :syn-priority:

> When several syntax items may match, these rules are used:
>
> 1. When multiple Match or Region items start in the same position, the item
> defined last has priority.
> 2. A Keyword has priority over Match and Region items.
> 3. An item that starts in an earlier position has priority over items that
> start in later positions.

Silas Silva

unread,
Jan 17, 2012, 1:05:18 PM1/17/12
to vim...@googlegroups.com
> You'll need to play with the contains keyword of your group to include
> the normal highlighting rules, or the matchgroup keyword. As explained
> at :help :syn-priority:

Thank you. I was trying wrongly. The following rule is simple and
works well:

syn region myFoo start='<foo>' end='</foo>'me=s-1 contains=xmlTag,xmlEndTag,xmlEntity

Thank you again!

--
Silas Silva

Reply all
Reply to author
Forward
0 new messages