You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the intention is to highlight 'foo' in the context below
self.foo
The entire expression can be matched using
syntax match Test /\vself\.\w+/ " (1)
And only the desired part can be highlighted using
syntax match Test /\vself\.\zs\w+\ze/ " (2)
However, in my case the markdown syntax was already loaded and (2) did no longer work despite that the very similar (1) was still working. I have narrowed it down to an expression similar to this:
syntax match LineStart "^" (3)
I would expect (1) and (2) to match the same every time and only differ in their highlighting, but (2) does not highlight anything when (3) is present
Reproduction
Data in file:
self.foo
Running
syntax clear
syntax match LineStart "^"
syntax match Test /\vself\.\w+/
hi link Test Folded
Result: self.foo
Expected: self.foo
Running
syntax clear
syntax match LineStart "^"
syntax match Test /\vself\.\zs\w+\ze/
hi link Test Folded
Result: self.foo
Expected: self.foo
Running
syntax clear
syntax match Test /\vself\.\zs\w+\ze/
hi link Test Folded
LineStart consumes s from self, so it can no longer be matched when at the start of the line. You can have zero-width items in pattern, but syntax rules can’t be zero-width.
Try using positive look-behinds instead: \v%(self\.)@5<=\w+: here match starts at f after dot and not s, so it is not affected by the fact that s was consumed by LineStart.
Note the difference between \zs/\ze and look-aheads/-behinds: \z* matches the whole pattern regardless of \z* and then part of the match is excluded from highlighting thus making pattern affected by a number of things including other matches in “non-matched” part. Look-aheads/-behinds match only the needed part from the very beginning, but are slower.
5 in the example is part of the optimization and makes engine examine only at most 5 preceding bytes to test whether \w+ is preceded by self\.. I hope some day this number will be determined automatically for such simple patterns.
Stemming from this thread on reddit
Issue
the intention is to highlight 'foo' in the context below
The entire expression can be matched using
And only the desired part can be highlighted using
However, in my case the markdown syntax was already loaded and (2) did no longer work despite that the very similar (1) was still working. I have narrowed it down to an expression similar to this:
I would expect (1) and (2) to match the same every time and only differ in their highlighting, but (2) does not highlight anything when (3) is present
Reproduction
Data in file:
Running
Result: self.foo
Expected: self.foo
Running
Result: self.foo
Expected: self.foo
Running
Result: self.foo
Expected: self.foo
Environment
All tests ran with
Output of vim --version
The text was updated successfully, but these errors were encountered: