Take the 2-minute tour ×

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:


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

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

You should try:


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
add comment

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
add comment

Your Answer


