5

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?

1 Answer 1

6

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, 2021 at 0:35

Your Answer

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

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