使用Vim修正HTML和PHP的缩进 [英] Correct indentation of HTML and PHP using Vim

查看:110
本文介绍了使用Vim修正HTML和PHP的缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Vim,并且我无法在PHP文件中获得正确的HTML缩进。

I've been using Vim for a while, and I can't get proper HTML indentation working in PHP files.

例如,我想要的是如下所示:

For example, what I want is for each child to be indented one tab more than it's parent, as shown below.

<?php
if(isset($sports)) {
    //Do something
?>
<div>
    <label>Uniform Size</label>
    <ul>
        <li class="left"><label for="s" class="small">S</label><input type="radio" name="size[]" value="S" id="s" class="radio" /></li>
        <li class="left"><label for="m" class="small">M</label><input type="radio" name="size[]" value="M" id="m" class="radio" /></li>
        <li class="left"><label for="l" class="small">L</label><input type="radio" name="size[]" value="L" id="l" class="radio" /></li>
        <li class="left"><label for="xl" class="small">XL</label><input type="radio" name="size[]" value="XL" id="xl" class="radio" /></li>
    </ul>
</div>
<?php
}
?>

使用 PHP-correct-Indent 脚本,代码的格式如下:

Using the PHP-correct-Indent script, the code results in being formatted as follows:

<?php
if(isset($sports)) {
    //Do something
?>
<div>
<label>Uniform Size</label>
<ul>
<li class="left"><label for="s" class="small">S</label><input type="radio" name="size[]" value="S" id="s" class="radio" /></li>
<li class="left"><label for="m" class="small">M</label><input type="radio" name="size[]" value="M" id="m" class="radio" /></li>
<li class="left"><label for="l" class="small">L</label><input type="radio" name="size[]" value="L" id="l" class="radio" /></li>
<li class="left"><label for="xl" class="small">XL</label><input type="radio" name="size[]" value="XL" id="xl" class="radio" /></li>
</ul>
</div>
<?php
}
?>

即使我使用缩进的HTML添加PHP代码,缩进也会被忽略, HTML代码没有任何缩进。

Even with indented HTML which I then add PHP code to, the indentation is ignored, moving new lines of HTML code without any indentation at all.

那么,有没有什么方法可以使用Vim来获取我希望在PHP文件中使用HTML的缩进格式?

So, is there any way that I can get the indentation format that I want working with HTML within PHP files, using Vim?

推荐答案

这仍然困扰着我。我只是决定最好的解决办法(对我个人而言)是这样的:

This still bothers me. I only just decided that the best work-around (for me personally) is this:

:set filetype=html

然后突出显示您的文字并点击 = 。繁荣! HTML格式化成功。 (不太理想,我知道,但至少可以工作。)

And then highlight your text and hit =. BOOM! HTML formatting succes. (Not ideal, I know, but at least it works.)

这篇关于使用Vim修正HTML和PHP的缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆