In this post, I want to present you some basic features of PHPStorm IDE, which could really speed up your coding process. Beware. You’ll not find here any fancy things – just basics. But still very helpful if you didn’t know it before.
Plugins
You can install plugins on Preferences > Plugins page.
Codeglance
Plugin page: https://plugins.jetbrains.com/plugin/7275-codeglance
This functionality is known from Sublime Text (which I can recommend, too).
This plugin allows you to preview the whole file you’re editing (kind of minimap). It’s displayed on the right side of your editor. You can use this to navigate through the code (drag and move). Below it’s marked with the red borders:
Emmet (now built-in)
It’s kind of dynamic templating system where you can extend simple “magic” snippet into working code. E.g. writing (and hitting TAB key after):
.row>.column.medium-6*4>p
will produce:
<div class="row">
<div class="column medium-6">
<p></p>
</div>
<div class="column medium-6">
<p></p>
</div>
<div class="column medium-6">
<p></p>
</div>
<div class="column medium-6">
<p></p>
</div>
</div>
Cool, right? And simple. And fast!
You can find more recipes on the project page: https://emmet.io/
Navigation
Here I want to highlight some basic techniques on how to navigate through your code. All functions can be found in the Navigation menu. The keyboard shortcuts are written for Windows system so if you’re using different OS – just check it in the navigation menu. Using these features directly from the keyboard will save you a lot of time.
Go to line (ctrl+l)
Truly self-explanatory. Additionally, you can specify the column you want to jump to. E.g. typing 3:5 will route you to the 3rd line and the 5th column.
Go to class (ctrl+o)
If you know your class names – use this to quickly jump to the class definition. After typing any part of the class name – you can see the rich autosuggest menu with full class names and file locations.
Go to symbol (ctrl+alt+o)
The same as above – but instead of classes it is a list of symbols like variables, methods, and functions.
Go to file (ctrl+shift+o)
With that one, you are able to jump to file or directory. All these three features can be additionally configured (e.g. to filter results more etc.).
Toggle bookmark (F3)
Simple – toggle source code bookmark for given line on or off. Small “checked” symbol is placed on the right of the line number. After doing that we can…
View bookmarks (ctrl+F3)
View and navigate through all defined bookmarks. Additionally, the snippet of the nearest code is presented. Very helpful.
Back/forward (ctrl+[ and ctrl+])
Go back and forward through places where your cursor was. So it’s very similar to back/forward feature knows from internet browsers.
Last edit location (ctrl+shift+backspace)
Similar to the above, but it helps you navigate only to places where changes have been made.
Go to the navigation bar (ctrl+arrow up)
Selects upper navigation bar (“breadcrumbs”) and allows you to navigate through it. Use arrows to change level and current element; use “enter” key to activate selection (which means changing a directory or opening a selected file).
File structure (ctrl+F12)
A quick preview of the current file structure. So all classes, methods, functions, variables – in one place, sorted. The good place to start when analyzing a new source file.
Next highlighted error (F2)
Go to next error found by PHPStorm. Great for fixing all syntax or code style issues in the file.
You can find more in the official PHPStorm documentation:
https://www.jetbrains.com/help/phpstorm/navigating-through-the-source-code.html
Editing
Duplicate (ctrl+d)
Simply duplicates content.
- After selecting part of the line – will copy and paste it after selection,
- If there is no selection – the whole line will be duplicated,
- Hitting ctrl+D while some code block is selected – will simply duplicate it.
Column selection mode / multiline editing (alt + mouse selection)
Allows you to select multiple lines (and have multiple cursors) – but without selecting all lines (only e.g. columns from 3 to 20).
I also recommend to use Sublime Text’s shortcut for that: ctrl+shift+L (needs to be defined in Preferences > Keymap).
It’s hard to describe it, so let’s see an example:
Find and Replace
In the newest version, you can simply select some code and hit ctrl+F3. This will place selected text in the find bar so you can simply press ctrl+g to find next occurrences.
That is obvious. But did you know that hitting win+g will adds next occurrence to selection and then you can use multiline cursor editing on it? It’s the same like using ctrl+d with Sublime Text.
Find, select, change – with one edit!
To find some string globally just select it and use the ctrl+shift+f shortcut. It will be placed in dialog window automatically. Of course, you can change it there. Clicking magnifying glass on the left will display search history.
You can use a regular expression, set matching mode, project scope to search etc. – very powerful and very fast (PHPStorm is indexing your files).
You can also replace texts globally (with similar functionality). Just press ctrl+r.
You can read more about here:
https://www.jetbrains.com/help/phpstorm/searching-through-the-source-code.html
Summary
Hope you learned something new during reading this post. Maybe you have some neat tricks too? If so – share with us leaving a comment!