<created>
  pat@c.com 
</created>

I want to replace the above with but the username may vary i.e,pat@c.com ,harry@c.com...

  <created>
   tom@c.com
  </created>

What is the command to replace this in vim

 %s/<created>\r*\r</created>/new string
link|improve this question

29% accept rate
feedback

1 Answer

up vote 0 down vote accepted

It worked for me like this:

%s/<created>\n\s*\w*@\w*\n<\/created>/newstring/

If you wanted to re-insert the e-mail address you can use:

%s/<created>\n\s*\(\w*@\w*\)\n<\/created>/newstring: \1/

A bit of explanation:

  • \n: newline
  • \s: spaces and tabs
  • \w: any word character
  • \( and \): capture what's inside
  • \1: use the first captured expression
link|improve this answer
1  
Try using a different delimiter for clarity, since you have "/" in your pattern: "%s#<created>\n\s*\w*@\w*\n</created>#newstring#". – BMDan Aug 6 '10 at 13:59
Thanks guys,This is the first time i got a reply for a vim editor question. – Hulk Aug 6 '10 at 14:12
Can u explain the above.Not working for me now.. – Hulk Aug 6 '10 at 14:25
@Hulk, updated my answer, how is not working? – chmeee Aug 10 '10 at 6:49
It is now....... – Hulk Aug 26 '10 at 5:19
feedback

Your Answer

 
or
required, but never shown

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