Suppose I would like to highlight text after //
as comments, but shall stop after a }
, for example:
Some Text **//Some Comments**
Some Text **//Some Comments}** More Text
What I prepared in my syntax file is
syn match MyComment "\v\/\/.*(\}|$){-}"
hi def link MyComment GruvboxGray
, where I used {-}
try to match the shortest content, but it does not work, still, everything after //
are matched as comments, not interrupted by a }
.
Is there a way to define the shortest match?
.*
will gobble up everything. Try something like (untested):[^}]{-}
\}
than}
right?\v
mode) that you need to escape}
here\v
"very magic" mode is a bit mysterious. I think in "very magic" mode, all ASCII characters except '0'-'9', 'a'-'z', 'A'-'Z' and '_' have a special meaning. However Friedrich's answer works without escaping}
. But, if in syntax file I definesyn match MyTest "\vxx\}"
andsyn match MyTest "\vyy}"
, thenhi def link MyTest GruvboxRed
, then in vi onlyxx}
will be red,yy}
won't. I'm confused.