Search code examples
regexvimvim-syntax-highlighting

Vim regex skip delimiters


I'm trying to create a vim syntax file, and I'd like to match the following bit of text:

@[one two three four]

Basically, I want to match one and two as two separate matches, and I don't care about three and four (or anything after them). I also don't want to include the @[ delimiter at the beginning of the expression.

I tried doing this with regions, like so:

syn region langParamOne matchgroup=langListStart start=/@\[/ end=/\s\|\]/
syn region langParamTwo matchgroup=langListStart start=/@\[\S\+\s\+/ end=/\s\|\]/

Unfortunately, not only does this look messy, but vim will only match one of the regions, since one contains the other.

How can I set up a match for this syntax, but not include the starting @[ in the match?


Solution

  • How about this:

    syn region langParam matchgroup=langListStart start=/@\[/ end=/\]/ contains=langParamOne,langParamTwo
    syn match langParamOne /\(@\[\)\@<=\S\+/ contained
    syn match langParamTwo /\(@\[\S\+\s\)\@<=\S\+/ contained