On Wed 18-Oct-06 9:20pm -0600, Peng Yu wrote:
> On 10/18/06, Bill McCarthy <[EMAIL PROTECTED]> wrote:
>> You're fairly close. Assuming you visually marked those
>> lines, this solution is magic:
>>
>> '<,'>s/\%(}}\)\@<!\n
>>
>> but this solution is very magic:
>>
>> '<,'>s/\v%(}})@<!\n
>>
>> :h /\@<!
>> :h /\v
> Could you please explain what these commands mean?
Sure, let's use the first one:
'<,'>s/\%(}}\)\@<!\n
(1) '<,'>s/pattern
After you mark the text to be modified, hitting ":"
gives you, on the command line, ":'<,'>". So all you
type is ":s/pattern" - the "'<,'>" is typed by Vim.
This command deletes the first occurrence of "pattern"
on each line in the range.
(2) Instead of "pattern" I used pat1\@<!pat2
That finds a "pat2" that is not followed by a "pat1".
(3) For "pat1" I used '\%(}}\)'
I don't want EOLs that follow "}}". However, \@<!
operates on the atom to its left so it would only
operate on the second "}" - there for I've grouped it
with a non-capturing \%(\).
(4) "pat2" is just the EOL which is "\n".
(5) Note that it is "pat2" that is found and replaced, not
"}}\n".
Here's a much simpler one, but its done in two steps and
would add an EOL to any embedded "}}":
'<,'>j|s/}}/&\r/g
This is equivalent to type two commands:
(1) '<,'>j
That joins all the lines in the range to just one line.
(2) s/}}/&\r/g
That substitute command operates on the single resulting
line of the join command command. Every '}}' will be
replaced by '}}\r'. Where the '&' is replaced by the
whole matched pattern and '\r' is an EOL (although '\n'
is an EOL in a pattern).
--
Best regards,
Bill