David Nash

Wordpress Guru Sydney

Strip <span> tags from HTML in vim

Posted on April 6, 2009

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

  1. Matt says:

    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!

    • David says:

      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!

      • David says:

        Sorry should have taken the time to really read what you’re asking… assuming you’re replacing the word “span” with whatever XML tag you want to get rid of, you should be right.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>