简体   繁体   中英

Vim - in HTML files, is auto indenting the closing tags possible?

Is it possible to get Vim to auto indent closing tags in HTML? Here is an illustration of the issue I am having:

在此输入图像描述

You can see that it indents the opening tags perfectly but when I have a closing tag, they don't indent in line with the opening one. To be clear here is how I would want that example to indent:

<div class="first">
    <div class="second">
        thing
    </div>
</div>

Is there a simple way to fix this?

I know about running gg=G to indent the file at the end but I'm specifically looking to get the indenting happening as I type.

As an aside, in Sublime Text 3 I get around the issue using Emmet – each time you expand it places the cursor in the correct position. However, the Vim version behaves oddly, failing to auto indent so that's not a possible solution either.

In case relevant, here is a link to my current .vimrc: https://gist.github.com/benfrain/f09dd39e66fe2da9cf0a

The behavior you ask for has been the default behavior for quite a while. The default Vim on Mac OS X (7.3.000, released in 2010) does that and the latest MacVim (7.4.258) does that too.

Could you post your ~/.vimrc , please?

edit

I tested your vimrc , with all the vundle stuff, all the mappings to non-existing commands, and generally stuff that couldn't work here (backupdir, colorscheme…) commented out and I get the normal and expected behavior.

I would suggest you bisect your vundle plugins.

FWIW, there are a few mistakes in your vimrc but they don't seem to have any impact on your current problem:

I would suggest installing one of the alternative HTML indentation plugins, which will also address other quirks in addition to closing tags:

http://www.vim.org/scripts/script.php?script_id=2075

http://www.vim.org/scripts/script.php?script_id=1830

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