1

I have several syntax match patterns, that logically belong together.

Currently I match them like this: syntax match FOO /\v<(foo1|foo2|foo3)>/

What I actually want to match is .foo1, .foo2 and .foo3. Here lies my problem: I cannot get the pattern to match the additional dot.

Here are some of my tries:

  • /\v<(\.foo1|\.foo2|\.foo3)>/
  • /\v<(.foo1|.foo2|.foo3)>/
  • /\.foo1|\.foo2|\.foo3)>/
  • /v<\(\.foo1|\.foo2|.foo3\)>/
  • /<(.foo1|.foo2|.foo3\)>/

And many more of similar combinations. Thanks in advance!

1 Answer 1

2

| separates atoms and dot makes vim unhappy about it so you could add additional braces syntax match FOO /\v(\.foo1>)|(\.foo2>)|(\.foo3>)/ or put a dot out of the branching:

syntax match FOO /\v\.<(foo1|foo2|foo3)>/
hi link FOO Statement

enter image description here

3
  • Your second suggestion works as intended! Thank you. I'd prefer your first solution, which only works partially for me: everything gets matched, but not the first entry (.foo1). However if I add any other string before, .foo1 will get matched. Do you have any idea why?
    – earthling
    Jan 13, 2022 at 13:52
  • 1
    syntax match FOO /\v(\.foo1>)|(\.foo2>)|(\.foo3>)/ should also work.
    – Maxim Kim
    Jan 13, 2022 at 14:21
  • Works like a charm, thanks a lot! This has been annoying me for quite some time :)
    – earthling
    Jan 13, 2022 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.