Domanda

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:

È stato utile?

Soluzione

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 :)

Altri suggerimenti

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 -
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top