使用 Vim 正確縮進 HTML 和 PHP
php問題
html5模板網
Correct indentation of HTML and PHP using Vim(使用 Vim 正確縮進 HTML 和 PHP)
本文介紹了使用 Vim 正確縮進 HTML 和 PHP的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我已經使用 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!