Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to beautify code in PhpStorm and other Intellij editors?

Tags:

phpstorm

Is there any way to beautify my php code in PhpStorm? (a keyboard shortcut would be preferable)

like image 318
Gopal Sharma Avatar asked Jan 05 '14 18:01

Gopal Sharma


People also ask

How do I add formatter XML to IntelliJ?

All you need is to export settings from Eclipse (go to Eclipse's Preferences → Java → Code Style → Formatter and export the settings to an XML file via the Export All button.), and then open IntelliJ IDEA Settings → Code Style → Java, click Manage, and import that XML file by simply clicking Import.

How do I run code style in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Editor | Code Style. To configure a scheme for new projects, go to File | New Projects Setup | Settings/Preferences for New Projects | Editor | Code Style. Select the language for which you want to configure the code style.

How do I fix indentation in IntelliJ?

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.


2 Answers

Choose Code | Reformat Code, or press Ctrl + Alt + L.

EDIT: The keyboard shortcode has changed since PHPStorm 10 for windows to Ctrl + Alt + F

like image 179
Staff Avatar answered Sep 22 '22 06:09

Staff


Select code to reformat and press Ctrl + Alt + Shift + L

This is tested and working (Ubuntu), cheers!

For Mac:

Select code to reformat and press Command + Alt + Shift + L

For full page code reformat Alt + Command + L

Tested in phpStorm 2018.1.1

like image 24
Ravistm Avatar answered Sep 24 '22 06:09

Ravistm