Jorenar / miniSnip

Lightweight snippet plugin for Vim
MIT License
53 stars 8 forks source link

Problems with indentation in HTML #25

Closed rsaihe closed 2 years ago

rsaihe commented 2 years ago

I've noticed that there seems to be one particular case that is not indented correctly.

Specifically, I have the following snippet for HTML files:

<<{}>>
  <{}>
</<{~1}>>

However, when I expand this, instead of the expected result (using div as an example):

<div>
  |
</div>

I get the following:

<div>
  |
  </div>

I'm not exactly sure why this particular case indents incorrectly, but I speculate it is related to the name of the closing tag itself being a placeholder.

rsaihe commented 2 years ago

Very interestingly, just after I finished writing the previous message I decided to test the same snippet in an XML file and it indented correctly, so it definitely is specific to Vim's indentation of HTML.

Jorenar commented 2 years ago

Yes, this is related to how Vim indents HTML. If you write it by hand, you get the following behaviour:

<div>
  test|
<div>
  test
  </div|
<div>
  test
</div>|

Notice how closing tag was re-indented after finishing it with >.
When you enter it via your snippet, the rule is not triggered since <<{}>> and </<{~1}>> aren't matching pair.

rsaihe commented 2 years ago

Ah, that makes sense. Any idea why it does still work in XML files?

Jorenar commented 2 years ago

Indentation for XML is implemented differently, because all XML tags need to have a closing tag, while in HTML not all of them. Thus when Vim sees any closing tag in XML, it just decreases the indent; while in HTML needs to check whether you are closing <li> or the <ul> above it.

rsaihe commented 2 years ago

Alright, I see.

Jorenar commented 2 years ago

Yeah, unfortunately, I don't see any straightforward way to fix the problem.