Vim regex for wrapping visually selected digits with HTML tags

2

1

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?

CSED

Posted 2012-09-20T14:30:00.463

Reputation: 25

Answers

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.

m4573r

Posted 2012-09-20T14:30:00.463

Reputation: 5 051

2

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

Atropo

Posted 2012-09-20T14:30:00.463

Reputation: 1 513

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 – 2012-09-20T15:31:59.457

Thanks for the suggestions. I though that the link was self-explanatory. – Atropo – 2012-09-25T10:04:31.163