简体   繁体   English

Vim - 在HTML文件中,是否可以自动缩进结束标记?

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

Is it possible to get Vim to auto indent closing tags in HTML? 是否有可能让Vim在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. 我知道在最后运行gg = G来缩进文件,但我特意想在输入时进行缩进。

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. 顺便说一句,在Sublime Text 3中,我使用Emmet解决了这个问题 - 每次展开它时都会将光标放在正确的位置。 However, the Vim version behaves oddly, failing to auto indent so that's not a possible solution either. 但是,Vim版本表现奇怪,无法自动缩进,因此这也不是一个可能的解决方案。

In case relevant, here is a link to my current .vimrc: https://gist.github.com/benfrain/f09dd39e66fe2da9cf0a 如果相关,这里是我当前.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. Mac OS X上的默认Vim(2010年发布的7.3.000)就是这样,而最新的MacVim(7.4.258)也是如此。

Could you post your ~/.vimrc , please? 你能发贴你的~/.vimrc吗?

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. 我测试了你的vimrc ,所有的vundle东西,所有映射到不存在的命令,以及通常在这里无法工作的东西(backupdir,colorscheme ...)注释掉,我得到正常和预期的行为。

I would suggest you bisect your vundle plugins. 我建议你将你的vundle插件平分。

FWIW, there are a few mistakes in your vimrc but they don't seem to have any impact on your current problem: FWIW,你的vimrc中有一些错误,但它们似乎对你当前的问题没有任何影响:

I would suggest installing one of the alternative HTML indentation plugins, which will also address other quirks in addition to closing tags: 我建议安装一个替代HTML缩进插件,除了关闭标签之外,它还将解决其他问题:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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