I can't find out how to join all lines till a next condition happens (a line with only 1 or more numbers) p.e.
input:
1
text text text text (with numbers)
text text text text (with numbers)
2
this text
text text text text (with numbers)
text text text
3
text text text text (with numbers)
4
etc
desidered output:
1 text text text text (with numbers) text text text text (with numbers)
2 this text text text text text (with numbers) text text text
3 text text text text (with numbers)
4
etc
I normally use global/^/,+2 join
but the number of lines to join are not always 3 in my example above.
Python String join() The string join() method returns a string by joining all the elements of an iterable (list, string, tuple), separated by the given separator.
You can have a string split across multiple lines by enclosing it in triple quotes. Alternatively, brackets can also be used to spread a string into different lines. Moreover, backslash works as a line continuation character in Python. You can use it to join text on separate lines and create a multiline string.
When you want to merge two lines into one, position the cursor anywhere on the first line, and press J to join the two lines. J joins the line the cursor is on with the line below. Repeat the last command ( J ) with the . to join the next line with the current line.
Instead of the static +2
end of the range for the :join
command, just specify a search range for the next line that only contains a number (/^\d\+$/
), and then join until the line before (-1
):
:global/^/,/^\d\+$/-1 join
v/^\d\+/-j
will do the trick.
v
execute the function for each not matching the condition
^\d\+
your condition : Line starting with a number.
-j
go one line backward an join. Or if you prefer join the current line with the previous line.
So basically we join every lines not matching your condition with the previous line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With