Strip <span> tags from HTML in vim

David Nash vim, xhtml 4 Comments

When upgrading a website you might see source code like this:

<span style="font-family: Arial; color: #0000ff; font-size: small;">Some text goes here</span>

You’re using CSS now and all those <span> tags are ruining it. In gvim, do this search and substitute:

%s/<span.\{-}>//g

Then to get rid of the </span> tags, do this:

:%s/<\/span>//g

Comments 4

  1. How would I enter this F&R in the GUI version of gVim? I have a a dozen XML files with a ton of articles in them and I need to scrape out a few thousand span tags, but when I search for your term, I get pattern not found. Any help would be great!

    1. With your gvim window active, on the keyboard hit “esc” and then shift-semicolon (to give you a colon, and put you in command mode – I think that’s what it’s called) and then %sblahblahblah

      Good luck, the learning curve is steep but you will get a lot of power!

Leave a Reply