htmlvimviindentation

How do I tidy up an HTML file's indentation in VI?


How do I fix the indentation of his huge html files which was all messed up?

I tried the usual "gg=G command, which is what I use to fix the indentation of code files. However, it didn't seem to work right on HTML files. It simply removed all the formatting.

I also tried setting :filetype = xml, to see if tricking it into thinking this was an XML file would help but it still didn't do it.


Solution

  • With filetype indent on inside my .vimrc, Vim indents HTML files quite nicely.

    Simple example with a shiftwidth of 2:

    <html>
      <body>
        <p>
        text
        </p>
      </body>
    </html>