Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a bunch of text I need to format via HTML, my main problem being that there's a bunch of digits at the beginning of certain words that I need to wrap with HTML tags. I'm trying to think up a vim regex that can help me achieve this but the furthest I've gotten is this:

:s:\(\d\):<sup>\1<\/sup>

This however only changes the first number in the line and not anything after that. Any ideas?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

You should try:

:s/\(\d\+\)/<sup>\1<\/sup>/g

The 2 problems you had with your command were:

  • \d matches only one digit. Add a + do match more
  • The /g in the end allows the substitution to continue after the first match.
share|improve this answer
    
Works like a charm, much obliged. Can't accept yet due to some strange 9 minute magic. –  CSED Sep 20 '12 at 14:36
    
Glad to help :) –  m4573r Sep 20 '12 at 14:39

You can do it with the surround plugin for VIM: https://github.com/tpope/vim-surround

share|improve this answer
    
Looks useful, I'll give it a shot. Thanks. –  CSED Sep 20 '12 at 14:55
    
Welcome to Super User! Your answer does not provide any information why or how the program can answer the question. Please take a look at these suggestions on how to provide great software recommendations. –  Daniel Beck Sep 20 '12 at 15:31
    
Thanks for the suggestions. I though that the link was self-explanatory. –  Atropo Sep 25 '12 at 10:04

Your Answer

 
discard

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.