2

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?

4

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.
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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