1

I have the following in .vimrc:

set tabstop=2 softtabstop=-1 shiftwidth=0 expandtab
filetype plugin indent on

When I type the following in an HTML file:

<html id="somethingverylong"
>
<head>

I expect the following indentation:

<html id="somethingverylong"
      >
  <head>

I want <head> to be indented two spaces. However, I get the following indentation:

<html id="somethingverylong"
      >
      <head>

How do I make Vim respect the shiftwidth setting and indent the inner tag with 2 spaces, instead of aligning with the closing >?

Vim version:

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug  2 2016 05:21:06)
Included patches: 1-2143
Compiled by Arch Linux
  • Why are you adding a newline before the first closing >? That seems both unnecessary and very ugly! – Karl Yngve Lervåg Aug 24 '16 at 5:17
  • @KarlYngveLervåg this is a simplified example. In the actual file, the outer tag has a lot of attributes aligned one under another. – Koterpillar Aug 24 '16 at 5:47
  • You're setting shiftwidth twice; The first one should probably be tabstop. At any rate, what you want doesn't seem supported by the html indent file. You can try and fix it by manually editing /usr/share/vim/vim74/indent/html.vim. – Martin Tournoij Aug 25 '16 at 20:04
  • @Carpetsmoker was indeed tabstop. – Koterpillar Aug 26 '16 at 23:06

Your Answer

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

Browse other questions tagged or ask your own question.