2

I've the following content:

group1
  item1
  item2
  item3
group2
  item4
  item5
group3
  item6

where I'd like to select all items which belong to group2 using a search range.

Here is my approach:

:/group2\n\zs/;,/^\ze\S/p

however it seems the \ze doesn't take any effect, because this is what is printed:

  item4
  item5
group3

I expect only item4 and item5 to be printed, without ending pattern (group3).

How do I exclude the ending pattern then?

1
  • 2
    That , is redundant btw. You could get the effect you want by changing ^ to \n in the second pattern, but you might be better off with offsets (e.g. :/^group2/+;/^group/-p) as noted in the accepted answer.
    – Antony
    Commented Dec 21, 2016 at 23:26

2 Answers 2

3

I could be wrong but I think the atom \ze does take effect, it just doesn't prevent Vim to find a match on the group3 line.
It's an empty match since you write \ze just after the anchor ^ which excludes everything afterwards. But even if it's empty, it's still something, the beginning of the line.

Maybe you could use an offset:

:/group2\n\zs/;,/^\ze\S/- p
                        ^
                        |___ minus sign, to decrease the line address by one
2

My approach

:g/group2/+1,/group3/-1p

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.