><p>1. I am good</p> ><p>2. You sucks!</p> ><p>3. Take that, moron</p> >I want to change those sentences into: ><p id="1">1. I am good</p> ><p id="2">2. You sucks!</p> ><p id="3">3. Take that, moron</p>
>How do I do that using vim replace command? >All I can think is this: >:%s/<p>\d/<p id="\d">\d/igc Me personally? I'd do something like :s/\(<p>\)\([0-9]*\)\(. \)/<p id="\2">\2\3/p Ie, first field is the "<p>", second is the index, third is the '. ' (you want to preserve the format, and not get any false hits), and replace with the new tag, and simply put back the 2nd/3rd fields.