Question

I have an HTML file that doesn't have any line breaks. Practically a huge portion of it is in a single line. I was trying to tidy that in Vim; I tried gg=G, which just tried to intend the first four lines that were on separate lines.

I tried that after the following commands:

:filetype indent on
:set filetype=html
:set smartindent

note:

Was it helpful?

Solution

You can probably do it without plugin :)

Test this

:s/<[^>]*>/\r&\r/g

to split lines then remove spaces with

:g/^$/d

finally

gg=G

Hope it works :)

OTHER TIPS

For reformatting and clean up of HTML, I usually pipe this through Tidy or html-beautify.js:

:%! tidy --indent yes --wrap 0 --tidy-mark no --force-output true -quiet --show-errors 0 --show-warnings 0
:%! html-beautify.js --file -
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top