Join lines between a certain text pattern in Vim
I have a text file which looks like this:
A.
text
text
text
A.
more text
more text
A.
more text
I want to join all lines between the "markers" A.
so that it looks like:
A.texttexttext
A.more textmore text
A.more text
How can I do this in Vim?
Solution 1:
:%s/\n\(\(A\.$\)\@!.*\)/\1/
Substitute a pattern matching:
- newline,
-
a group containing of
-
not the string
A.
directly followed by end-of-line, then - any character until end of line
-
not the string
with:
- everything matched except the starting newline (i.e. the group above),
and do this globally.
Solution 2:
This also works (when the first line starts with A.
)
:v/^A/-1j!