6

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.

tirenweb
  • 197
  • 3

2 Answers2

3

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.

wisbucky
  • 950
  • 8
  • 6
2

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
mMontu
  • 6,630
  • 21
  • 31