Given the following example:
aa
aa
bb
bb
cc
dd
I'm trying to replace two-line match (bb\nbb
) with its first matching line (bb
).
What works:
- these two-lines can be matched by:
/bb\_.\{-}bb
(as per: Search across multiple lines), - I can replace two-line match with hardcoded one-line string:
%s/bb\_.\{-}bb/foo/g
.
What doesn't work:
I can't use first backreference (
\1
) instead of hardcoded string, so when using:%s/bb\ze\_.\{-}bb/\1/g
as result of just adding
\ze
and\1
to the previous example, I expect that this two-line pattern would be replaced by its backreference value (sobb\nbb
becomesbb
), but instead it removes the 1st line and not touching the 2nd. (sobb\nbb
becomes:\nbb
).
Any idea why the following attempt doesn't work? I don't want to join and remove the second line, I'd like to understand what's the problem and what's the correct way of doing it.