#php #ide #phpstorm

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.


Hi, I am Samgan, I excel at solving complex problems involving logic and step by step breakdown of the problem. Besides, to develop complex algorithms, I specialise in problem framing, systems design, and product development strategy. Sometimes I also enjoy public speaking.  

I am also the creator of penit.ink, a site which provides young writers with a free hand place to show their creation to the world. Irrespective of the niche, if you write this place is defiantly for you.