6

I'm having trouble with vim wanting to treat the p element as an inline element rather than a block level one. What vim's auto indent should produce is:

<body>
  <p>
    Aaaaaaaaaaaaaa bbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc dd
    eeeeeeeeeeeee ffffffffffffff gggggggggggggggggggggggggggggggg eee
  <p>
</body>

but when typing this out and going to the second line in the paragraph, vim will move the indentation inwards one space like so:

<body>
  <p>
  Aaaaaaaaaaaaaa bbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc dd
  eeeeeeeeeeeee ffffffffffffff gggggggggggggggggggggggggggggggg eee
  <p>
</body>

I think this is because most people write their html like this:

<body>
  <p>Aaaaaaaaaaaaaa bbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc
     eeeeeeeeeeeee ffffffffffffff gggggggggggggggggggggggggggggggg<p>
</body>

How can I get around this and make vim format all block level elements in the same manner?

  • 3
    Everything is explained in :help html-indent. – romainl Jun 19 '15 at 22:00
3

I had to add the code below to my vimrc to get the p tag to work. I also included all the block level elements that are listed in the link in the original question as well (though this is overkill) to prevent any other changes (like Vim patch 7.4.356) from overriding my preferred settings.

"
" HTML indentation
"

let g:html_indent_script1 = "inc"
let g:html_indent_style1 = "inc"
let g:html_indent_inctags = "address,article,aside,audio,blockquote,canvas,dd,div,dl,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,main,nav,noscript,ol,output,p,pre,section,table,tfoot,ul,video"

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.