We all have our favorite IDEs or editors in which we write code. For me, this is PhpStorm, and it took some time to master all the keyboard shortcuts and speed up my workflow. In this article, I will share with you some keyboard shortcuts and tips that will take on part of the routine work if you do your job in this IDE too. This article was partially inspired by this Reddit thread, and I will mention and demonstrate some of the tricks found there.
Please note that I am developing on Linux in Vagrant, hosted on Windows, I will use the CTRL key instead of the CMD. If you are running OS X, replace CTRL with CMD. ')
Keyboard shortcuts and khaki
PhpStorm allows you to customize yourself almost indefinitely - you can sharpen this tool for yourself so that it may seem to an outsider that this is a completely different IDE.
(careful, many gif images) Let's see what we can use: ( in brackets next to the abbreviations are the names of the functions in the keymap )
CTRL+ALT+L ( Reformat Code ), one of my most used combos, formats your code in accordance with the selected code design settings:
In addition, as you can see in the pop-up window that appears in the above animation, you can choose to reformat the entire project. If there is a need to use this feature often and at the same time you are not so much working on other people's projects, then take note - it is possible to link the CTRL+Smacro and auto-format the code with each save. But it is worth noting, however, that if you are working on a project with someone else, this can lead to too frequent changes in code formatting and pollute the version control system.
If you are in Linux, the CTRL+ALT+L combination may already be associated with “Screen Lock”, and you will need to unlink it in the system settings or change it in the PhpStorm settings.
By pressing CTRL+SHIFT+Backspace ( Last Edition Location ), or using the “Forward” and “Back” mouse buttons (if you have them), you will move to the previous editing location. This is very useful when working with large files:
Holding CTRL while hovering over variables or methods will give you additional information, and Ctrl+ on a variable or method, or pressing CTRL+B ( Declaration ) when the cursor is set on a method or on a variable will lead you right to where it is defined:
CTRL+ ( Basic ) will bring up a pop-up window with hints if you accidentally closed it or it didn’t open for some reason:
When PhpStorm detects any problems, it will highlight the problem area and cause a tooltip on top of it when you hover the mouse or the keyboard cursor in that area. Clicking on it or pressing Alt+Enter ( Show Intention Actions ) will be offered a solution. This behavior can be changed by turning off error reports (I do not recommend this):
CTRL+N ( Class ), and CTRL+SHIFT+N ( File ) allow you to instantly move to any part of a class or project file:
the search is fuzzy and also supports line numbers - you can use abbreviations :XX , where XX is the line number:
PhpStorm remembers the last few clipboard values ​​- you can press CTRL+SHIFT+V ( Paste from History ) to bring up a pop-up window that allows you to paste previously used contents of the clipboard.
If you are in love with the ability of Sublime to search by the commands of the IDE itself, then you can do this in PhpStorm - CTRL+SHIFT+A ( Fine Action ) will cause a pop-up window for finding commands. Forgot your shorthand for reformatting code? Just press CTRL+SHIFT+A and type “Refor ..”:
You can generate HTML using Emmet built into PhpStorm. Just type div#myDiv>span.mySpanClass>ul>li*5 and press TAB and get:
You can expand these features for any language by adding your templates in Settings -> Editor -> Live Templates . Detailed description of Emmet for CSS and HTML here .
Perhaps somewhat unintuitively, CTRL+W ( Select Word at Caret ) (which is most often used to close a tab, so that you can reassign it) will select blocks of code under the cursor (word, variable, etc.). Repeating a combination extends the selection, including the parent node, for example:
Context-sensitive editing allows you to edit a code snippet written in another language in a separate editor. For example, if you have the HTML snippet contained in the PHP line, press Alt+Enter above this line and select Edit HTML :
The column selection mode can be triggered by holding the middle mouse button (wheel) and dragging. For me, this is especially useful when you need to copy a part of the code with a deep indentation, but ignoring unnecessary spaces:
Pressing Alt+Home ( Jump to Navigation Bar ) will allow you to use the cursors to move along the navigation chain at the top. ESC outputs from this mode:
Refactoring (renaming) variables and applying changes at once in all places that use - SHIFT+ALT+CTRL+T ( Refactor This ) call the refactoring menu, as shown in the animation below:
CTRL+F12 ( File Structure ) will pop up a window that allows you to select a method in the current file that you want to go to. Despite the fact that there is no search field, as soon as you start typing, the choice will be narrowed down to the options that you are looking for.
This tweet tells us that you can now “search everywhere” by pressing Shift twice. This is a powerful mix of all previous search abbreviations, allowing you to find everything you need in any part of a project or IDE - from IDE commands to classes and function declarations, and much more.