Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to replace the above with but the username may vary i.e, ,


What is the command to replace this in vim

 %s/<created>\r*\r</created>/new string
share|improve this question
up vote 0 down vote accepted

It worked for me like this:


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
share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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