2

I would like to know how to highlight multiple tokens in the same line.

For example, if I want to highlight the value of 'a', I can write something like this:

syn match num  'a=\zs\d\+\ze,b=\d\+.*'

This would highlight the number 42 in a=42,b=5.

Now what if I want to highlight both numbers? I know that something like 'a=\zs\d\+\ze,b=\zs\d\+\ze.*' won't work because it only highlights the last number.

Please note that I don't want to highlight all the numbers in the line, so if I have a string like (a=1,b=2,c=3), I only want to highlight 1 and 2 (i.e. the values of a and b).

Edit: Also note that a and b should be adjacent, with b following a. So (a=1,b=2,b=3) should highlight only 1 and 2.

2

Given that:

so if I have a string like z=5,a=1,b=2,c=3, I only want to highlight 1 and 2 (i.e. the values of a and b).

This works:

syn match Number "[ab]=\zs\d\+"

Or this:

syn match Number "\(^\|[\s,]\)[ab]=\zs\d\+"

The below one won't match variables like faaa=.. or xxxb=

  • I did not make myself clear enough, please check the edited question. – Kira Nov 11 '15 at 16:35
  • 1
    @Kira It is long time I haven't written syntax file. I have to test with your example. however I don't get time right now. But I think you need to use the contains, contained and nextgroup check :h syn-nextgroup for detail, there is an example. – Kent Nov 11 '15 at 17:14

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.