2

I have a style element in an HTML file. When I type, NeoVim continuously indents each successive line:

bad indentation

In my Vim, it works correctly:

correct indentation

My vimrc.

I would be grateful for any suggestion. Thanks!

  • I can't reproduce this on Neovim v0.3.1 with a minimal filetype plugin indent on setup. What does :set inde? ai? si? give you? Do you possibly have a plugin installed with its own indent file for CSS? You can check with: :filter /indent/ scriptnames. – ZeroKnight Sep 17 '18 at 21:30
  • Strange. I loaded neovim with a minimal "filetype plugin indent" and still have the same issue. I'm using version v0.3.1 as well. – Zoltan King Sep 19 '18 at 19:25
  • My brain got stuck on "css" and tested with a css file and not an html file as in your example. I can reproduce this behavior with nvim -u NONE -c ':filetype plugin indent on | :e test.html'. HtmlIndent() is definitely the cause. – ZeroKnight Sep 19 '18 at 20:04
  • For the record, I get the same indenting behavior in Vim 8 as well. – ZeroKnight Sep 19 '18 at 20:12
  • 1
    @paxdiablo Okay, sorry about that. I'm still getting used to how much is okay to edit; I'll keep that in mind. – ZeroKnight Sep 20 '18 at 18:08
2

This particular issue seems to have come up more than once:

Unfortunately the replies and answers mostly consist of non-solutions (suggesting to turn off filetype entirely) or workarounds (set indentkeys+=;). After a lot of digging, I gained more useful knowledge.

Quick History

The current indent/html.vim that ships with the (Neo)Vim runtime is a fork of Andy Wokula's indent file. This fork was originally created and is currently maintained by Bram himself in 2014. It is this overhaul where this CSS-indentation bug was first introduced; Andy's original HTML indent file did not have this indentation issue. Ever since then, it has remained.

...Until very recently!

A very recent upstream commit (22 days ago from the time of writing) included an update to indent/html.vim that fixes the CSS-indentation. Adding this upstream version to ~/<vimfiles>/indent and reproducing the example in your question gives the desired behavior.

Solution

Add the indent/html.vim from the current Vim upstream to your vimfiles:

  • Neovim: ~/.config/nvim/indent
  • Vim: ~/.vim/indent

And of course, make sure that filetype plugin indent on exists somewhere in your configuration.


* This question predates the overhaul fork in 2014, but presents the same symptoms. Perhaps the 2007 version happened to have the same issue?

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.