Since my last system update (I think), I have noticed this very annoying behavior.

# vim foo.html
# I go to insert mode, I type (no whitespace except newlines)

  • That's four tabs in front of that <script>, instead of two.
  • The two extra tabs are added right when I type that final closing >.
  • With set softtabstop=2 shiftwidth=2 expandtab it's the same, but spaces.
  • The other tags don't matter, the <script> can be anywhere like "^\s+<script>".
  • It doesn't happen when <script> has any other attribute (like a src, type or foo="bar")... could this be a bug?
  • UPDATE: when I type a closing </script> in the same line the extra indentation is removed with, again, the final >.
# .vimrc
filetype plugin indent on

# vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 17 2020 21:54:53)
Included patches: 1-1704
Compiled by Arch Linux
  • 2
    Probably bug in indent plugin of html.
    – Maxim Kim
    Oct 27 '20 at 11:07
  • 2
    Welcome to Vi and Vim! I'm inclined to agree with @MaximKim based on the very minimal vimrc you show. I get 3*2 spaces with my config, but <esc>== actually fixes it? the JS indenting inside <script> is generally not too great
    – D. Ben Knoble
    Oct 27 '20 at 13:19
  • 1
    Looks like 7ff78465f broke it; if I revert that then <script> will actually be on the same indent as <head>, which isn't really correct either. I don't really know what a fix is, but you can put a copy of indent/html.vim in ~/.vim/indent/html.vim without this change to get the old behaviour back. Oct 27 '20 at 22:18
  • Thanks @MartinTournoij et al, I've filed an issue
    – kubi
    Oct 28 '20 at 13:22

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.