hhh
hhh

Reputation: 52860

Vim: how to join inline linebreaks in free text fields?

I have free text

"starthello","hello 
 helloInline
 helloInline2","hello2","new field"
"not this","no inline line breaks","no","no"

where I would like to join it with "$^ " to

"starthello","hello helloInline helloInline2","hello2","new field"
"not this","no inline line breaks","no","no"

How can I join inline line breaks in Vim?

Upvotes: 0

Views: 54

Answers (2)

DJMcMayhem
DJMcMayhem

Reputation: 7689

You can do this:

:g/[^"]$/.,/"/j

Here's how it works:

:g/                 # On every line matching this regex:
   [^"]$            #   A line that does *not* end with a double quote
        /           # Run this command:
         .,         #   On every line from the current line until
           /"/      #   The next line containing a double quote
                    #   Run this command:
              j     #     Join (remove newlines)

Upvotes: 2

sid-m
sid-m

Reputation: 1554

There might be other ways to do this, but one way would be to visually select the lines you want to join by pressing Shift+V and moving cursor up or down. Then pressing Shift + J to join the selected lines.

Upvotes: 1

Related Questions