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


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>:


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.

1 Answer 1


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 html-indenting.

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, 2016 at 0:09
  • @Antony Fascinating! I didn't know about the = key until now! (:help =)
    – Flimm
    Nov 7, 2016 at 11:17
  • @Antony Hi, could you maybe clarify what you mean? Thanks!
    – zyy
    Oct 17, 2021 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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