2

I've created a blank example.html file and I open it in Vim, and I add the following contents:

<div>

Still in insert mode, at the end of the line, if I press enter, the new line will automatically be indented for when I type <p>:

<div>
        <p>

Clearly, something knows that <div> expects children, which should be indented, and is indenting the following line automatically for me. What is enabling this? How do I disable this, without disabling other automatic indentation features like :set autoindent copyindent?

Note that :set smartindent? displays nosmartindent, so it's not that.

5

It turns out that Vim ships with a bunch of indent.vim files (enabled with :filetype indent on), including one for HTML. You can read help for it at :help indent-html.

This HTML indent file sets indentexpr option to a function that knows how to parse HTML. When indentexpr is set, it overrules cindent and smartindent. If you want to disable it, run :set indentexpr=.

If you want to always disable it, put this in your .vimrc file:

au FileType html,htmldjango setlocal indentexpr=
  • 2
    You might instead setlocal indentkeys= That way you can still use = to indent lines on demand if you wish. – Antony Nov 4 '16 at 0:09
  • @Antony Fascinating! I didn't know about the = key until now! (:help =) – Flimm Nov 7 '16 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.