Hi, Nikolaos A. Patsopoulos wrote: > > I have a text that has many occurrences of a pattern . I want to delete > every consecutive occurrence, e.g. > > Pattern Pattern other text Pattern Pattern Pattern Pattern other text > Pattern Pattern Pattern > should look like this: > Pattern other text Pattern other text Pattern > > I've used: > > :%s/\(Pattern\s\+\)\(Pattern\)/\1/g > > but have to run this more than once with: %&g to result the wanted text. > > Can I do this with one command only?
if you want to remove multiple occurrences of the same *pattern*, use :%s/\(Pattern\)\(\s\+Pattern\)*/\1/g But if you want to remove multiple occurrences of the same *text*, use :%s/\(Pattern\)\(\s\+\1\)*/\1/g There is a noticeable difference if your pattern is not a simple text but a more complex regular expressions, e.g. :%s/\(\d\+\)\(\s\+\d\+\)*/\1/g would turn 42 00 00 00 43 00 00 00 into 42 while :%s/\(\d\+\)\(\s\+\1\)*/\1/g would result in 42 00 43 00 Regards, Jürgen -- Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us. (Calvin)
