# HTML is not being indented

I have just created a file .html. When I run set filetype? I get filetype=html. Then I select this code:

<div>
<span>
</span>
</div>


and press = but the code is not indented... I don't have problems to indent php files for example using the same procedure.

• Make sure you have set :filetype plugin indent on The indent part is important – Christian Brabandt Jan 20 '16 at 14:19
• What's the output of :scriptnames after you open an HTML file? – muru Jan 20 '16 at 15:47

Try checking the options mentioned in :help =:

={motion}   Filter {motion} lines through the external program
given with the 'equalprg' option.  When the 'equalprg'
option is empty (this is the default), use the
internal formatting function |C-indenting| and
|'lisp'|.  But when 'indentexpr' is not empty, it will
be used instead |indent-expression|.  When Vim was
compiled without internal formatting then the "indent"
program is used as a last resort.


If it is working in php files, try comparing the values of the relevant options in each of them.

Your example works fine here, and the command :4verbose setlocal equalprg indentexpr prints the following:

  equalprg=
indentexpr=HtmlIndent()
Last set from /usr/local/share/vim/vim74/indent/html.vim

• what I get from 4verbose setlocal equalprg indentexpr is this: equalprg= indentexpr= – ziiweb Jan 20 '16 at 14:19

I tried your sample (result below), so vim's html autoformat/indent definitely works with this.

<div>
<span>
</span>
</div>


Here's the steps to do it:

:filetype plugin indent on " enable the filetype indent plugin
:e                         " re-open the file (very important!)
:scriptnames               " make sure you see an ".../indent/html.vim"
:=G                        " or whatever range you want


scriptnames is the key to identifying whether the indent/html.vim is properly loaded. If not, then you probably need to re-open the file.

Note that if you put filetype plugin indent on in the ~/.vimrc, then you won't need to re-open the file since that plugin was already enabled before you opened the file.