Last Updated: February 25, 2016
· jacaetevha

tidied HTML in vi/vim

If you have Tidy installed, just pipe your buffer through it to get clean HTML.

:%!tidy -qicbn -asxhtml

Use "tidy -h" for more help on the options, but the ones I tend to go with are in the example above:

-indent, -i         indent element content
-clean, -c          replace FONT, NOBR and CENTER tags by CSS
-bare, -b           strip out smart quotes and em dashes, etc.
-numeric, -n        output numeric rather than named entities
-quiet, -q          suppress nonessential output
-asxml, -asxhtml    convert HTML to well formed XHTML

3 Responses
Add your response


If all you want to do is fix indenting, and you have filetype=html, then you can highlight a range of text and hit "=".

over 1 year ago ·

Thanks @petdance, but Tidy does much more than just fix indentation.

over 1 year ago ·

And beware if you have SVG embedded.

over 1 year ago ·