Here's a heavy-weight solution that gets you indenting, plus all the HTML pretty-printing you don't necessarily want to care about while you're editing.
First, download Tidy. Make sure you add the binary to your path, so you can call it from any location.
Next, create a config file describing your favorite HTML flavor. Documentation is not great for Tidy, but here's an overview, and a list of all the options. Here's my config file:
bare: yes
break-before-br: no
clean: yes
drop-proprietary-attributes: yes
fix-uri: yes
indent-spaces: 4
indent: yes
logical-emphasis: yes
markup: yes
output-xhtml: yes
quiet: yes
quote-marks: yes
replace-color: yes
tab-size: 4
uppercase-tags: no
vertical-space: yes
word-2000: yes
wrap: 0
Save this as tidyrc_html.txt
in your ftplugin
folder (under vimfiles).
One more file: add the following line to (or create) html.vim
, also in ftplugin
:
map <leader>tidy :%! tidy -config ~/vimfiles/ftplugin/tidyrc_html.txt <CR>
To use it, just open an HTML file, and type /tidy
. (That /
is the <leader>
key.)
There you go! Not a quick solution, by any means, but now you're a bit better equipped for editing those huge, messed-up HTML files.