2

I'm trying to get Vim (version 7.4), running on Ubuntu (14.04 LTS), to apply automatic indentation to HTML files. I know from the answers to this question that several tags you'd expect to cause indentation are not indented by default in Vim 7.4, and I know that's not the problem. Even the <div> tag, which should cause indentation in the default configuration, does not result in any indentation for me. If I type in the minimal example from this question, I get the following:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test page</title>
</head>
<body>
<div>
<p>This is a paragraph.</p>
</div>
</body>
</html>

Note that the <p> is not indented inside the <div>. Even if I save the file and do gg=G, Vim displays 12 lines indented but the <p> remains unindented.

My .vimrc has the required lines

set autoindent
filetype indent plugin on
set shiftwidth=4
set tabstop=4

If I do :set filetype? while editing the example HTML file, I get filetype=html so the filetype is getting detected properly, and /usr/share/vim/vim74/indent/html.vim exists. Furthermore, syntax highlighting is correct for HTML, so at least some filetype-specific files are getting loaded correctly.

Does anyone know why the indenting rules aren't being applied to HTML files?

Community
  • 1
  • 1
Edward
  • 5,942
  • 4
  • 38
  • 55
  • Everything is explained in `:help ft-html-indent`. – romainl Feb 02 '16 at 19:53
  • Uh, no it isn't. That help section explains how to use `g:html_indent_inctags` to add additional tags that should be indented, but my problem is that even the default tags that should be indented out-of-the-box (such as `
    `) are not getting indented.
    – Edward Feb 02 '16 at 20:50
  • Uh, yes it is. `g:html_indent_inctags` is empty by default, you need to add tags to it: `g:html_indent_inctags='html,body,head,...'`. – romainl Feb 02 '16 at 21:23
  • That variable represents *additional* tags to indent beyond the default ones, as documented here: http://stackoverflow.com/a/19330009/1500563. Either way, though, if I `:let g:html_indent_inctacs='div'` and re-apply indenting with `=`, the `

    ` inside the `

    ` is still not indented at all.
    – Edward Feb 02 '16 at 22:15

0 Answers0