PhpStorm – Top Productivity Hacks and Shortcuts

We all have our favorite IDEs/editors when coding. Mine is PhpStorm, and it took a while to master all its shortcuts and establish a rapid workflow. In this article, I’ll share some keyboard shortcuts and tips with you which you should make part of your regular routine if you, too, do your work in this IDE. This article was partially inspired by this Reddit thread, and will be mentioning and demonstrating some of the shortcuts found there as well.

Note that as I’m doing my development on Linux in a vagrant box hosted on Windows, my shortcuts might be different from yours. The JetBrains reference card matches them up perfectly and gives you the OS X alternatives: Reference Card.

Keyboard shortcuts and hacks

PhpStorm’s high configurability (it’s almost an “Android” of the PHP IDE world) lets you fine tune it to infinity – you can make it into a tool so personal, it might seem like a different IDE to anyone opening your settings. Let’s see some shortcuts and hacks we can take advantage of:

  • CTRL + ALT + L, one of my most used keyboard combos, will immediately format your code according to the preferred style guidelines:

    What’s more, as you can see by the popup that appears in the animation above, you can choose to reformat your entire project. If you use this excessively and don’t often work on other people’s projects, you take it up another notch – bind a macro to the CTRL+S shortcut, and make PhpStorm automatically reformat your code on every manual save. Note, however, that if you’re working on a project with someone else, this might cause refactors in various files far too often, and pollute your version control system with changes that aren’t changes at all. If you’re on Linux, your CTRL+ALT+L shortcut might already be bound to “Lock Screen”, and you’ll need to unbind it from the system, or change it in PhpStorm’s settings.

  • Pressing CTRL+SHIFT+Backspace, or the “Forward” and “Back” buttons on your mouse if you have them, will walk you through your previous edit locations. This is very useful when dealing with large files and having to reference another part only to come back to the original to continue the work:

  • Holding down CTRL when hovering over variables or methods will give you their full names or locations of declaration, while CTRL+Clicking on a variable or method, or pressing CTRL+B when on a method’s call or on a variable will take you directly to where it’s defined:

  • CTRL+Space will summon a code hinting dialog, if you accidentally closed it or for some reason it didn’t open:

  • When PhpStorm detects some problems, it will underline the problematic area and summon a lightblub on top of it when you hover your mouse or keyboard cursor in that area. Clicking this light bulb or pressing ALT+Enter will suggest solutions – in any language. This can range from turning off error reports for suppressed notices (something I recommend against), to merging CSS rules:

  • CTRL+N and CTRL+SHIFT+N will let you instantly move to any part of any class or file in your entire project:

    The search is fuzzy, and also supports line numbers – you can use abbreviations followed by :XX where XX is the line number:

  • PhpStorm remembers multiple clipboard contents – you can press CTRL+SHIFT+V to summon a popup which lets you paste clipboard content that’s less recent than the latest.

  • If you’re in love with Sublime’s ability to search for commands of the IDE itself, you can do that too. CTRL+SHIFT+A will spawn a command search popup. Forgot how the code reformat shortcut goes? Just CTRL+SHIFT+A and type “refor..”:

  • Generate full HTML without writing it out, using Emmet, built into PhpStorm. Typing div#myDiv>span.mySpanClass>ul>li*5 and hitting tab will turn into:

    Further extend this in any language of your choice by adding your own expandable templates into the Settings -> Editor -> Live Templates dialog. You can choose where to position your cursor, add variables, and much more. The full Emmet cheat sheet for CSS and HTML can be found here.

  • Perhaps somewhat counter-intuitively, CTRL+W (which is most often used for closing tabs, so you may want to remap it) will select a “unit” of code under your cursor (a word, a variable, etc). Repeating the combination then expands the selection to include the parent node – all the way to the entire file (e.g. function call -> instance and function call -> row -> entire row -> method -> containing class…):

  • Context-aware editing will allow you to edit a string that’s written in another language in a dedicated editor, complete with code hinting and autocompletion. For example, you if you have an HTML snippet written in a PHP string, you can ALT+ENTER in the string’s content and select Edit HTML content. This happens:

  • Column selection mode can be summoned by holding the middle mouse button down and dragging over a piece of code. I’ve found this especially useful when I need to paste a deeply indented part of my code, but don’t want the preceding whitespace copied as well:

  • Pressing ALT+Home will let you use your cursors to move through the breadcrumb navigation at the top. ESC escapes this mode and returns you to the editor, unless you make a file selection in the breadcrumbs – then the file is immediately in focus.

  • Refactoring (renaming) variables and applying the change to all locations that use it is as easy as selecting right-click -> refactor, pressing SHIFT+F6 or even pressing SHIFT+ALT+CTRL+T to summon the entire refactor menu as shown in the animation below:

  • CTRL+F12 will summon a popup that lets you select a method in the current file to which you want to jump. Even though there’s no search field, if you just start typing you can narrow the selection down to exactly what you’re looking for.

  • As described in this tweet, you can now “search everywhere” by double-tapping Shift. This is like a powerful blend of all previous search shortcuts, allowing you to find anything you need in any part of the project or IDE – from IDE commands to classes and function declarations and more.

Plugins

PhpStorm has a wealth of various language plugins. I, for one, make heavy use of the Dart plugin for PhpStorm. This isn’t the type of plugin I’d like to talk about, though – there’s a plethora of productivity plugins, too. Plugins adding features you never thought a PHP IDE might have:

  • The combination of DynamicReturnType plugin with a good dependency injector, as described by Danack, will let you do proper IoC and still keep all your autocompletion and code inspection as if dealing with the classes directly. A more detailed article on using this particular combination will be published soon.

  • The key promoter plugin shows you the keyboard shortcut to your mouse actions as you perform them. If you use certain actions a lot, and they don’t have a keyboard shortcut, it will ask you if you’d like to add it.

  • CSS-X-Fire allows you to edit your CSS in Chrome’s Firebug lite, or Firefox’s Firebug, and on switching back to PhpStorm, you’ll be asked if you’d like to apply the changes you made in the browser to the CSS in your project’s code.

  • You might know that PhpStorm is a project-based IDE, meaning it cannot open and edit arbitrary non-project files like a regular text editor. This can be awkward when you need to brainstorm something or just write some notes for yourself but don’t want to pollute your project’s folder. Scratch lets you use temporary files in your projects for that exact purpose.

Dark themes for readability

Many people underestimate a good theme, dismissing it outright as flair or pure vanity. This is wrong – a good theme is a good user experience – it increases readability and makes you notice errors, keywords and all the syntax spice intuitively, without having to think about it. There are several benefits to using dark themes:

  • when looking at a bright display, your eyes get fatigued faster, especially at night (which is when most programmers tend to do their work). On dark displays, instead of focusing on the entire bright screen and trying to discern holes in it (darkness – letters), your eyes are immediately drawn to the bright parts – the text, ignoring the background altogether.
  • I subjectively claim that colors are easier to notice when on darker backgrounds. Naturally, this means the colors should have a decent, but not too strong contrast to the background
  • It’s a known fact that blue light from self-lit displays suppresses melatonin, which in turn disrupts your sleep patterns. If you find yourself having difficulty falling asleep after a 4AM coding session despite feeling utterly obliterated by fatigue, try a darker theme and exposing yourself to less light in general when working at night.

Things to look for in a theme are mid-range contrasts. Avoid absolutes – the background shouldn’t be pure black, and the text shouldn’t be pure white/red/green/orange. These sharp contrasts confuse and strain the eye just as much as having an all-white background and all-dark text does. Instead, look for pastel, smokey colors. Likewise, increasing the font is usually a good idea, if the theme’s default is tiny. The eyes strain when reading too small letters, and if the spacing isn’t good enough either, you’ll have a hard time reading anything without welcoming a headache. Two of my suggestions for darker themes are Darcula, which comes built into PhpStorm, and Solarized.

Apart from the generally more pleasant color scheme in Darcula (shown above), I’m the type of developer who uses comments extensively in my projects, so having them more legible but still not distracting is a valuable perk. The project structure is also, in my opinion, far more readable in the second screenshot – the light blue vs. gray contrast seems optimal to my eye.

While most theme preference discussions are, admittedly, subjective, I encourage you to venture outside your eyes’ comfort zone for a day or two and give alternatives a go. You’d be surprised at how fast you can adapt to the new style if you find one that particularly matches you.

Conclusion

In this article, we covered and demonstrated some popular and/or extremely useful keyboard shortcuts and productivity hacks for PhpStorm – an IDE that’s far more customizable than one might assume at first glance. What are your tips and productivity hacks? Do you see any missing? Let us know in the comments below and we’ll add them!

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • Nguyen Tuan

    great and useful!

  • tunepk

    What about multi-select? We all love Multiselect in SublimeText..please?

  • Ariel Bluman

    Inject HTML in pycharm (3.1) breaks if i use multiline htmls =

    there is shortcut for scrolling through suggestions?
    for example:
    use -> -> User -> -> UseSomthing

    • http://www.bitfalls.com/ Bruno Skvorc

      Not sure I understand the question? You have problems with Emmet?

  • http://www.dev-metal.com/ Chris

    Fantastic, thanks! I totally love the way PHPStorm’s creators have built PHPStorm (and their other IDEs btw): Everything is clever, intuitive, well-thought, easy to use, full of little details, optimized for speed and workflow. I would have bought it for the git handling alone, but there’s so much more … If you never tried PHPStorm, then give it a try, it will change your workflow dramatically.

  • Vincent Clair

    I have used many IDEs on Mac : Eclipse / Aptana Studio / Zend Studio, NetBeans or phpDesigner (and not so IDE as Coda or RapidWeaver). PHPStorm is far the more suited for me, really usefull and well designed.

  • http://foxinni.com/ Malan Joubert

    Brought tears to my eyes.

  • kiwi

    Can we have the same shortcuts on mac ?

    • http://www.bitfalls.com/ Bruno Skvorc

      “Note that as I’m doing my development on Linux in a vagrant box hosted on Windows, I’ll be using CTRL instead of CMD. If you’re on OS X, just imagine it says CMD.”

      If they’re not the same when you replace CTRL with CMD, just open the command browser (CMD+SHIFT+A) or the “search everywhere” popup (double Shift) and search for the command by name – you’ll see the keyboard shortcut there too.

    • http://www.bitfalls.com/ Bruno Skvorc
  • http://www.bitfalls.com/ Bruno Skvorc

    You’re welcome!

  • Aleksandar Ristić

    CTRL + ALT + L is for locking the screen on KUBUNTU, can’t use it for PHPStorm :) I’ve started using this IDE 5-6 months ago, it’s great!

    • http://www.bitfalls.com/ Bruno Skvorc

      Like I say in the article “If you’re on Linux, your CTRL+ALT+L shortcut might already be bound to “Lock Screen”, and you’ll need to unbind it from the system, or change it in PhpStorm’s settings.”

  • Tobias Hochgürtel

    I suggest, great and useful article. I created some notes on my desk.

  • mbaroz

    Great tips!
    I love this IDE. but I need it to support FTP editing without downloading the while FTP files. Any idea? Or plugin?
    Thanks.

  • saeba

    Hello, I have a small problem with shortcuts in last PhpStorm. I’m on Linuxmint 16 and shortcuts Alt+Number (like Alt + 6 for todo list) doesn’t work. All other shortcuts without Alt key work perfectly :( Can someone help me ? Thanks

    • http://www.bitfalls.com/ Bruno Skvorc
      • saeba

        Thanks! The shortcuts Alt+Number don’t exist on this doc

        • http://www.bitfalls.com/ Bruno Skvorc

          See “General”, second row. Is that not it?

          • saeba

            Yes that’s it, I’m still sleeping :o but this shortcut doesn’t work for me on linuxmint, but ok on windows 7. Strange problem. Thanks

  • Elfet

    Look at my theme for PhpStrom: https://github.com/elfet/oblivion

  • http://www.bitfalls.com/ Bruno Skvorc

    It’s not just about the RAM, PhpStorm is very disk intensive – it works hard to index everything and provide super fast code hints. On my SSD, it runs everything instantly and loads up fully in 3-4 seconds.

  • http://www.bitfalls.com/ Bruno Skvorc

    Thanks for the heads up!

  • mbadolato

    For a darker theme, we have one that’s based on the online docs for Symfony2 and Doctrine: https://github.com/cordoval/Symfony2Colors

  • Gareth Davies

    Nice article. I’ve found a printed version of the official reference card a handy resource too http://www.jetbrains.com/phpstorm/documentation/PhpStorm_ReferenceCard.pdf

  • Jose Ruzafa

    very good article thanks for sharing, it has served me well since I use your advice much php.

  • http://www.bitfalls.com/ Bruno Skvorc

    Not sure. Which PhpStorm do you have? Anyway, here, have my settings, maybe they’ll help, I’m on Win8.1 too: https://dl.dropboxusercontent.com/u/1473908/settings.jar

    • Srinivas J R

      Thank you again. I’ve used your settings, still no improvement. Anyway I’ve PhpStorm 7.1.2, I’ll try from PhpStorm support.
      Wonderful post and will definitely improve my usage of PhpStorm.

      • http://www.bitfalls.com/ Bruno Skvorc

        Cheers, let us know what you find out!

  • John Bertucci

    Great article. I also use the plugin CodeGlance. http://plugins.jetbrains.com/plugin/7275?pr= to get that very zoomed out view of your file. And I moved my file “tabs” to go vertical instead of horizontal since I end up with so many files open with big file names. That was just a change in the IDE settings.

    • http://www.bitfalls.com/ Bruno Skvorc

      Excellent plugin and a good point about the vertical tab names, thanks

  • Sebastien Barre

    Great writeup! I’m a long-time PhpStorm user and I learned a bunch of stuff here.

    For your comment about blue light affecting sleep patterns when working at night, you should check out f.lux at http://justgetflux.com/ it’s a great little tool that changes your monitor’s colour range to a warmer tone as the sun goes down and makes it much easier on your eyes.

    This little tool has vastly improved my nighttime coding.

    • http://www.bitfalls.com/ Bruno Skvorc

      Whoa, that’s a fantastic tool. Trying it out this very weekend, thanks!

  • Codrut Bila

    how would you rate html5 buider [ embarcadero ] vs phpstorm? thks.

    • http://www.bitfalls.com/ Bruno Skvorc

      You probably mean RAD studio, which includes the Html builder. I haven’t tried it, so I don’t know, but any software that isn’t available on all OS is a dead start from me.

  • Bionik6

    Nice article, see nothing new for me here because I spend a lot of time configuring my IDE. Think for many years that nothing was best than Netbeans when it comes to develop but when I’ve switched to PHPStorm, I’ve really seen the difference, very customizable, many features and so on….
    Wonder they fully integrate Laravel in the next versions of the IDE :)

  • http://ngocpham.info/ Ngoc Pham

    I don’t really know why but whenever I try to increase the font size (for the editor) to 14, all lines become “funky” with some sort of unaligned. I’m on a Mac, with latest 7.1.2 version of PhpStorm. Does anybody get this problem?

    Another big problem for me is as soon as I start the app, it eats up approximately 500MB of memory. I know it’s an IDE, and Java-based, so it’s understandable, but I really want something more light-weight.

    • http://www.bitfalls.com/ Bruno Skvorc

      The memory will rarely move after that, though. Yes, it’s big chunk, but considering the features, it’s still more lightweight than the competition. I haven’t encountered the font issues.

  • http://www.ericlin.me Eric Lin

    CTRL + SHIFT + F in Mac will allow you to find text under a path or the whole project & CMD + SHIFT + UP/DOWN keys allows you to move selected lines up or down.