1

what is the global command that will join lines that start with more than one space?

I have tried this but it does not work as expected:

:g/ \{2,}//J

Example:

I want to turn this:

01:001:001 In the beginning God created the heaven and the earth.
01:001:002 And the earth was without form, and void; and darkness was
           upon the face of the deep. And the Spirit of God moved upon
           the face of the waters.
01:001:003 And God said, Let there be light: and there was light.
01:001:004 And God saw the light, that it was good: and God divided the
           light from the darkness.
01:001:005 And God called the light Day, and the darkness he called
           Night. And the evening and the morning were the first day.
01:001:006 And God said, Let there be a firmament in the midst of the
           waters, and let it divide the waters from the waters.
01:001:007 And God made the firmament, and divided the waters which were
           under the firmament from the waters which were above the
           firmament: and it was so.
01:001:008 And God called the firmament Heaven. And the evening and the
           morning were the second day.
01:001:009 And God said, Let the waters under the heaven be gathered
           together unto one place, and let the dry land appear: and it
           was so.

Into this:

01:001:001 In the beginning God created the heaven and the earth.
01:001:002 And the earth was without form, and void; and darkness was upon the face of the deep. And the
Spirit of God moved upon the face of the waters.
01:001:003 And God said, Let there be light: and there was light.
01:001:004 And God saw the light, that it was good: and God divided the light from the darkness.
01:001:005 And God called the light Day, and the darkness he called Night. And the evening and the mornin
g were the first day.
01:001:006 And God said, Let there be a firmament in the midst of the waters, and let it divide the water
s from the waters.
01:001:007 And God made the firmament, and divided the waters which were under the firmament from the wat
ers which were above the firmament: and it was so.
01:001:008 And God called the firmament Heaven. And the evening and the morning were the second day.
01:001:009 And God said, Let the waters under the heaven be gathered together unto one place, and let the
 dry land appear: and it was so.
0

1 Answer 1

2

Turns out since I need to join current line to above line and not the below line to the current line, -j has to be used like so:

:g/ \{2,}/-j
1
  • 2
    Good job. However, though it works fine for your example it would break if you had 2+ spaces in the interior of a non-indented line. Therefore, a "more correct" and more generally usable answer would have a "start of line" anchor at the beginning of the pattern: :g/^ \{2,}/-j. Commented Nov 15, 2021 at 0:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.