magic is happening

How to format file in PhpStorm

If you are habitual of writing a formatted code don’t worry it’s a good habit but when sometimes you get to debug files which are not formatted what so ever. In that case, it’s a headache to get things done in that sort of files.

In this kind of scenario, PhpStorm comes to rescue, Normal indentation of the file can be done only by the following commands.

Ctrl + A (to select complete file)
Ctrl + Alt + I (this will indent the file properly.)

But sometimes we need more than just indentation. To completely format file got for

Ctrl + Shift + Alt + l

This will open a dialogue box, easy to understand. Select as you are pleased and go for it. This will format your file as you wished it was.

Moreover, sometimes a file is full of unused commented code which is there for no use. I tried for searching a plugin or something to remove all that commented code at ones but I guess there isn’t any.

But found a good solution to this problem. You can use search and replace with regular expression with the following regex.

Multi line comment: /\*(\*)?(((?!\*/)[\s\S])+)?\*/
Single line comment: //.*$

And replace them with empty and we are good to go.

If you also got some more tricks down your sleeves feel free to comment.

Leave a Reply

Your email address will not be published. Required fields are marked *

Close
Social profiles