Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indentation of HTML in PHP files within PhpStorm

In a .php file I have a the following code

<? include 'header.php' ?>
    <form action="/">
        <input>
    </form>
<? include 'footer.php' ?>

How can I delete the 4 indents before the HTML tag when I press Ctrl+Alt+L? It should look like this:

<? include 'header.php' ?>
<form action="/">
    <input>
</form>
<? include 'footer.php' ?>
like image 650
J.Menshov Avatar asked Jul 21 '16 08:07

J.Menshov


People also ask

How do I indent in PhpStorm?

While in the editor, select the necessary code fragment and press Ctrl+Alt+I . If you need to adjust indentation settings, in the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | Code Style. On the appropriate language page, on the Tabs and Indents tab, specify the appropriate indents options and click OK.

Does PhpStorm support HTML?

PhpStorm brings powerful support for HTML that includes syntax and error highlighting, formatting according to the code style, structure validation, code completion, on-the-fly preview during a debugging session (Live Edit) or in the dedicated preview tab in the code editor, and much more.

Does PHP use indentation?

Spacing and indentation should be consistent throughout your code. Many developers choose to use 4-space or 2-space indentation. In PHP, each nested statement (e.g., a statement following a "{" brace) should be indented exactly once more than the previous line's indentation.

Does prettier work with PHP?

Intro. Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary. This plugin adds support for the PHP language to Prettier.


2 Answers

It's a bug with PhpStorm. Until it is fixed, simply put a new line after your last closing PHP tag.

<? include 'header.php' ?>
<form action="/">
    <input>
</form>
<? include 'footer.php' ?>
// new line here
like image 84
Daerik Avatar answered Nov 05 '22 22:11

Daerik


The Ctrl+Alt+L is the shortcut for Reformat Code, which automatically applies the code indentation rules set in the PhpStorm settings.

It is currently not possible to make the code look like you want automatically. You would have to format the code manually every time.

The reason is the limitation of the PhpStorm formatting engine. There is already feature request at the PhpStorm issue tracker which addresses the issue: WI-32401
Also see this issue report: WI-17786

like image 43
Kevin Woblick Avatar answered Nov 05 '22 20:11

Kevin Woblick