Tim Chase wrote:
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
Tim, Peter and Jorgen,
thank you for your replies. It was too easy after all. :)
Nikos
--
Nikolaos A. Patsopoulos, MD
Department of Hygiene and Epidemiology
University of Ioannina School of Medicine
University Campus
Ioannina 45110
Greece
Tel: (+30) 26510-97804
mobile: +30 6972882016
Fax: (+30) 26510-97853 (care of Nikolaos A. Patsopoulos)
e-mail: [EMAIL PROTECTED]