> I want to join all lines that are inside a given pattern and occurs more > than once in the text, ie: > > .... > PatternStart .... > ....text1 > ....text2 > ...text3 > ..text4 > PatternEnd > > PatternStart ........text1....text2...text3..text4PatternEnd > > I tried to use: > :g/PatternStart\_.\{-}PatternEnd/ J > > but this joins only first and second line of the pattern. > > How can I tell vi to join all lines inside all occurrences of this > pattern with variable containing lines?
You're very close: :g/PatternStart/,/PatternEnd/j should do the trick. This is a slightly shorter way of writing :g/PatternStart/.,/PatternEnd/j where it's easier to see the pattern of :g/{regexp}/{action} where {action} is ".,/PatternEnd/j". This {action} uses the desired range of lines rather than just joining one line to its following line (as "j" without a range does). If you want to keep the whitespace, you can use "j!" instead of "j"...otherwise, Vim will collapse multiple whitespace characters into a single space (perhaps trying to be smart after a period or other certain punctuation and putting two spaces?) -tim