Note that there are some explanatory texts on larger screens.

plurals
  1. POCorrect indentation of HTML and PHP using Vim
    text
    copied!<p>I've been using Vim for a while, and I can't get proper HTML indentation working in PHP files.</p> <p>For example, what I want is for each child to be indented one tab more than it's parent, as shown below.</p> <pre><code>&lt;?php if(isset($sports)) { //Do something ?&gt; &lt;div&gt; &lt;label&gt;Uniform Size&lt;/label&gt; &lt;ul&gt; &lt;li class="left"&gt;&lt;label for="s" class="small"&gt;S&lt;/label&gt;&lt;input type="radio" name="size[]" value="S" id="s" class="radio" /&gt;&lt;/li&gt; &lt;li class="left"&gt;&lt;label for="m" class="small"&gt;M&lt;/label&gt;&lt;input type="radio" name="size[]" value="M" id="m" class="radio" /&gt;&lt;/li&gt; &lt;li class="left"&gt;&lt;label for="l" class="small"&gt;L&lt;/label&gt;&lt;input type="radio" name="size[]" value="L" id="l" class="radio" /&gt;&lt;/li&gt; &lt;li class="left"&gt;&lt;label for="xl" class="small"&gt;XL&lt;/label&gt;&lt;input type="radio" name="size[]" value="XL" id="xl" class="radio" /&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;?php } ?&gt; </code></pre> <p>Using the <a href="http://www.vim.org/scripts/script.php?script_id=1120" rel="noreferrer">PHP-correct-Indent</a> script, the code results in being formatted as follows:</p> <pre><code>&lt;?php if(isset($sports)) { //Do something ?&gt; &lt;div&gt; &lt;label&gt;Uniform Size&lt;/label&gt; &lt;ul&gt; &lt;li class="left"&gt;&lt;label for="s" class="small"&gt;S&lt;/label&gt;&lt;input type="radio" name="size[]" value="S" id="s" class="radio" /&gt;&lt;/li&gt; &lt;li class="left"&gt;&lt;label for="m" class="small"&gt;M&lt;/label&gt;&lt;input type="radio" name="size[]" value="M" id="m" class="radio" /&gt;&lt;/li&gt; &lt;li class="left"&gt;&lt;label for="l" class="small"&gt;L&lt;/label&gt;&lt;input type="radio" name="size[]" value="L" id="l" class="radio" /&gt;&lt;/li&gt; &lt;li class="left"&gt;&lt;label for="xl" class="small"&gt;XL&lt;/label&gt;&lt;input type="radio" name="size[]" value="XL" id="xl" class="radio" /&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;?php } ?&gt; </code></pre> <p>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.</p> <p>So, is there any way that I can get the indentation format that I want working with HTML within PHP files, using Vim?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload