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' ?>
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.
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.
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With