Packetizer Logo
 

Using Vim to Convert HTML Tags from Uppercase to Lowercase

September 3, 2009

Sometimes, a good tip is worth sharing. As I was making some edits to some HTML pages using Vim, I wanted to find a quick way to convert uppercase tag and attribute names to lowercase. I found this tip somewhere on the Internet and it worked so well, I thought it might be worth repeating.

To convert HTML tags from uppercase to lowercase, use this command in Vim:

Source Code

%s/<\/\?\zs\(\w\+\)\ze[ >]/\L\1/g

To convert HTML attributes from uppercase to lowercase, use this command in Vim:

Source Code

%s/\(<[^>]*\)\@<=\<\(\a*\)\ze=['"]/\L\2/g

Click here to view the main blog page.