使用 Vim 正确缩进 HTML 和 PHP

Correct indentation of HTML and PHP using Vim(使用 Vim 正确缩进 HTML 和 PHP)
本文介绍了使用 Vim 正确缩进 HTML 和 PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我已经使用 Vim 一段时间了,但我无法在 PHP 文件中使用正确的 HTML 缩进.

例如,我希望每个子项比其父项多缩进一个制表符,如下所示.

<div><label>统一尺寸</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>

<?php}?>

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

<div><label>统一尺寸</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>

<?php}?>

即使使用缩进的 HTML,然后我将 PHP 代码添加到其中,缩进也会被忽略,移动 HTML 代码的新行而根本没有任何缩进.

那么,有什么方法可以使用 Vim 获得我想要在 PHP 文件中处理 HTML 的缩进格式吗?

解决方案

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

:set filetype=html

然后突出显示您的文本并点击=.繁荣!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
}
?>

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
}
?>

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.

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

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

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Subtract time in PHP(在 PHP 中减去时间)
Limit execution time of an function or command PHP(限制函数或命令 PHP 的执行时间)
How to sum N number of time (HH:MM Format)?(如何求和 N 次(HH:MM 格式)?)
How to get current time in milliseconds in PHP?(如何在 PHP 中以毫秒为单位获取当前时间?)
How to check if time is between two times in PHP(如何检查时间是否在 PHP 中的两次之间)
Convert number of minutes into hours amp; minutes using PHP(将分钟数转换为小时数分钟使用 PHP)