3

I have text bounded by quotes as follows

"This is
an example
of some text"

I want to join these into one line. e.g.

"This is an example of some text"

I have tried commands like the following:

:g/^"\_[^"]\+"$/j

However, while this matches the text I'm looking for, it appears to only join on the first line.

I think this is due to :g only working with the first line of the match. Is there another way to do this?

5

I found something on the Vim wiki that combines ranges with searches.

This command did the trick for me:

:g/^"/,/"$/j

e.g.

:g         (global)
/^"/,/"$/  (a range between a line starting with ", and a line ending with ")
j          (join the lines specified in the range)
1
  • 2
    Note that we assume that every time we have a quote at the start of a line, it is followed by a quote at the end of another line. This was true for me, but may not be true for you!
    – daviewales
    Feb 15 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.