简体   繁体   中英

VIM indentation: HTML comment with <openedTag> inside comment

Vim indents HTML blocks as soon as it finds the closing HTML-tag pair , even if it is inside a comment .

How can I indent as desired? Please

 <:-- Right indentation: --> <div class="x"> <!-- div --> <h1>Title</h1> </div> <!-- Wrong indentation: --> <div class="x"> <!-- <div> --> <h1>Title</h1> </div>

Btw, toogling these changes nothing

:set smartindent!
:set cindent!

Maybe following link gives a clue to a brighter person than me: Vim Wrong Indent When There Is Dash - in Html Tag

You can try with something like

:inoremap ,, <c-o><<<c-o>O

and then type ,, after closing tag (for ex. after </div>) to "fix" the wrong indentation by indenting it 1 level backwards.

You could also map some other key combination in insert mode instead of 2 commas.

This would help only in insert mode, but not if you reformat the whole buffer for ex. via '='.

From Vi iMproved (VIM) by Steve Oualline it explains how not to limit syntax of quotes " in a line, and only attend to start/end of line quotes.

[...] a region start (double quote) and a region end (double quote).The definition is as follows:

:syntax region xString start=/”/ end=/”/

The start and end directives define the patterns used to define the start and end of the region. But what about strings that look like this?

“A string with a double quote (\”) in it”

This creates a problem:The double quotation marks in the middle of the string will end the string.You need to tell Vim to skip over any escaped double quotes in the string.You do this with the skip keyword:

:syntax region xString start=/”/ skip=/\\”/ end=/”/

Maybe these syntaxes rules have something to do with indentation's.

And maybe the answer is solved applying and alike strategy with <div> </div> as Mr. Qualline does with " " .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM