If I have a <table> element it indents


However, if I do the same thing with a <p> tag, it does not indent:

enter image description here

Why the difference here? Is there a way I can get it to indent equally after every html/xml tag? (for example, like it does for the table item)?

  • 1
    Your second question is addressed here (defining indents for a given tag...there's no "all tags do this" option, though): :h html-indent
    – B Layer
    Apr 29 '20 at 4:13

The authors of the HTML indentation script shipped by Vim seem to have decided not to indent inside tags such as <p> because they are "self-closing" tags, meaning that the closing </p> is optional. I imagine the rationale for that is that, if a </p> was omitted by the user, the indentation wouldn't have been retracted, so each new paragraph would get indented further and further.

See this comment in $VIMRUNTIMES/indent/html.vim:

Self-closing tags and tags that are sometimes self-closing (e.g., <p>) are not here (when encountering </p> we can find the matching <p>, but not the other way around).

Known self-closing tags: p, img, source, area, keygen, track, wbr.

You can override this behavior and extend the list of tags that increment indentation by setting the g:html_indent_inctags to a comma-separated list of additional tags that should require indentation.

In your case:

let g:html_indent_inctags = 'p'

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.