Reputation: 654
I've a syntax after file for Java. It works, cause I already defined some syntax keywords, matches and regions, which are successfully highlighted.
Not I want to highlight some matches, which are within a highlight region I defined before. My intention was that the region get highlighted first and the matches afterwards draw over this region parts.
The exact use case are the function/class/... descriptions with thei documentation keywords like @author
, @version
, ... Therfore I wrote the following into my syntax file:
syntax region _Comment start="\/\*" end="\*\/"
syntax match _CommentKey "^\s*\*\s*\zs@\w*\ze\s"
highlight link _Comment Comment
highlight link _CommentKey Special
No I have two problems. I test both independently and the comment region works fine. The comment key match only works without the \zs
part, so it highlight also the leading *
. As soon as I add the \zs
nothing is highlighted anymore. How can I solve this? For other matches this works fine.
The second problem: I don't them combined. If I enable both rules, only the whole section will be highlighted as Comment
. I doesn't matter where I place the second rule, it will not be highlighted. Also I tried to use the skip
for the region, until I realiszed it is meant for something different.
Any ideas? Thanks!
Example code to test:
/**
* Function description here.
*
* @param id
* @author Max Mustermann
*/
private static int function foo(final int id) {
return id;
}
Upvotes: 1
Views: 2281
Reputation: 6026
Syntax regions, which have nested matches must allow them:
syntax region _Comment start="\/\*" end="\*\/" contains=_CommentKey
Have a look at :h syn-contains
For your first Problem, you should read :h syn-pattern
there you'll find the following sentence:
Syntax patterns are always interpreted like the 'magic' option is set, no matter what the actual value of 'magic' is.
See :h magic
for that. Your regex must escape @
in magic mode.
"^\s*\*\s*\zs\@\w*\ze\s"
should work fine
Upvotes: 2