2

I'm trying to get % to match custom keyword pairs

With vim matchit, I can do

let b:match_words=
            \ '\<Start\>:\<Stop\>' 

to match Start and Stop.

I would like to match Start with either Stop or Stop2. How can I do this?

I have tried

let b:match_words=
            \ '\<Start\>:\<Stop\>,' .
            \ '\<Start\>:\<Stop2\>' 

but then % only jumps from Stop/Stop2 to Start but not from Start to Stop2.

I also have instances where I'd like where multiple possible start words should match with a single stop word (I don't think I have one where both the start and the stop have multiple spellings, if this matters.)

How can this kind of matching be done in vim?

3

The matchit plug-in takes regular expressions for its matches from b:match_words, so you can easily use a regular expression that matches both possible end keywords to accomplish that.

For your specific case:

let b:match_words= '\<Start\>:\<Stop2\?\>'

But assuming the end keywords a don't have any common parts, let's say Stop or Finish, then you can use:

let b:match_words= '\<Start\>:\<\(Stop\|Finish\)\>'

See :help b:match_words for all the details on what is supported through that setting.

| improve this answer | |
  • Thanks. Had tried ?, but without the `\`. Gotta get used to vim style regexes. :) – PSkocik Jan 10 at 10:38
  • 1
    @PSkocik Same here! There's \v you can use to make them "very magic" but those can also take some getting used to... Glad this fixed it for you! – filbranden Jan 10 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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