On 11/01/11 06:03, RJA wrote:
if I have the buffer below,

ppppp 1 2 3 4 5
ppppp 1 2 3 4 5
ppppv 1 2 3 4 5
ppppp 1 2 3 4 5

I can type the search

/\(ppppp\).*\n\1.*

which will match against the first two lines

However, I want to pick out lines 2 and 3. How can I do that ?

For this particular case, you can search for

  ^\(.....\).*\n\1\@!

Note that the "\@!" matches the previous atom, so if you're doing something more complex than the single "\1" atom, you need to wrap it in grouping-parens, whether capturing "\(...\)" or non-capturing "\%(...\)".

Also note that the 4th (last) line will be matched because the following line doesn't start with the pattern on the current line. If you want to mitigate, just change the pattern to

  ^\(.....\).*\n\1\@!.....

to assert there are 5 things there. Thosse "....." could also be written as ".\{5}" for what it's worth.

For more reading, you can

  :help /\@!

and the surrounding sections regarding the Perl-ish tokens.

-tim



--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to