Skip to main content

8 Must Use Shortcuts for PhpStorm

Apr 08 '15

PhpStorm is a very powerful IDE that has a load of features for almost any project setup scenario. Even if it doesn’t support your setup out of the box there are numerous plugins to fill in the gaps. As is often the case when interacting with something so advanced, it is easy to get overwhelmed and you can miss the little things that can greatly increase productivity.

Here are some things that I use almost daily on projects. Note that I work on a Mac and, as such, I’m pulling the Windows hotkeys from the documentation. If I’ve got one wrong, you can find it under preferences in [Editor > Keymap].

phpstorm shortcuts

1. Go to Declaration

- Mac: Command + B while cursor is on symbol

- Windows: Control + B while cursor is on symbol

So, you found a function being used in your class, registerAcmeProviders(), but have no idea where that function is defined. This hotkey takes you on a magic carpet ride directly to it (Aladdin won't be singing you any Tim Rice songs, unfortunately). You can use this on functions, variables, classes, and other symbols. If you forget the hotkey you can also right- click the symbol and [Go To... > Declaration].

2. Find Usages

- Mac: Option + F7

- Windows: Alt + F7

Imagine the reverse scenario of the previous tip. You are at the function declaration of registerAcmeProviders(), but you don't know where that function is being used. This hotkey will give you a list of usages for you to peruse. This is useful for when you need to add/edit a parameter to a function or are trying to cleanup and remove potentially unused code.

3. Format Document

- Mac: Command + Option + L

- Windows: Control + Alt + L

Did you just inherit a project that appears to be written by one-armed lemurs? Or maybe you were up way too late last night coding and apparently you forgot where the tab key was? No sweat - PhpStorm has a built-in code formatter for scenarios such as these. Using this hotkey will clean up your code based on the rules you've set up in the preferences under Editor > Code Style. If you are using this on a project under source control such as git or SVN, you can tell the formatter to only format the changed text. This is handy when you just want to format your newly added code, but not check in a bunch changes to the file that are not part of your update.

4. Quick Rename

- Mac: Control + R

- Windows: Shift + F6

D'oh! You misspelled your variable, `amceValue`. Shouldn't that be `acmeValue`? Easy peezy. Go to the variable and hit this hotkey and put in the fixed name. PhpStorm will intelligently refactor your code (even across multiple files!) to fix your typo.

5. Quick Search by Filename

- Mac: Command + Shift + O

- Windows: Control + Shift + N

Tired of looking through a bunch of folders trying to find where AcmeServiceProviderFactory.php is? Just hit this hotkey and start typing the name of the file. PhpStorm will give you a list of possibilities. It is even smart enough to do partial searches based on words if your file is named with CamelCased or underscores. So, you remembered that file had Acme and Factory in the name but you can't remember the parts in between? No problem, PhpStorm has your back.

6. Quick Search by Symbol

- Mac: Command + Option + O

- Windows: Ctrl + Shift + Alt + N

Ok, so you remember the class name, AcmeServiceProviderFactory, but you don't remember what file it was put in? This command will search within files find any symbols (class names, functions, properties, etc.) that match your query. Protip: This can also be used to search CSS classes/IDs so you can find every instance of .section-acme-box in your project.

7. Search Actions/Options

- Mac: Command + Shift + A

- Windows: Control + Shift + A

Need to do some action that just KNOW is in one of the menu dropdowns but can't find it? This hotkey will let you search and run it directly. No more having to remember if `Optimize Imports...` is in [Code] or [Refactor]. Hint: it's in [Code]. Protip: You can also use this to search the preferences - neat!

8. Find in Path

- Mac: Command + Shift + F

- Windows: Control + Shift + F

You've been given a task to change the website tagline "Acme Rules!" to "Acme is ok" and for some reason the tagline was hardcoded in an unknown file nested deep somewhere in the abyss of template layouts and partials. Instead of pulling your hair out, just do a search with this hotkey and it will give you all instances of that tagline. For advanced users, you can also do regex searches.

Bonus: Search Everything

Search all the things! This command is not mapped to a hotkey by default, but I suggest adding one. (Hint: Remember to use Search Actions/Options to find it easily). Use this when you absolutely, positively must brute-force your way into finding something. PhpStorm will attempt to bend space-time and give you what you need.