Vim syntax file. match 'foo' and 'bar' independently in 'foobar'

In vim syntax file I want

  • name one match foo

    followed bybar

  • and another bar

    that followsfoo

And let them both work.

That's what I have so far

 syn match myFoo /foo\zebar/ display

 syn match myBar /foo\zsbar/ display

      

When I do this, it only matches the latter. I cannot get both foo

and bar

.

+3


source to share


1 answer


Try the following:

syn match myFoo /foo/ contained
syn match myBar /bar/ contained
syn match myFooBar /foobar/ contains=myFoo,myBar

      

I have confirmed that it works. I have Vim coloring foobar where foo is one color and bar is another color. And this only happens if they are together as foobar; otherwise they are not colored. I assigned them to different categories:



hi def link myFoo Keyword
hi def link myBar Type

      

You probably closed this already.

+3


source







All Articles