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.
You can install plugins on Preferences > Plugins page.
Plugin page: https://plugins.jetbrains.com/plugin/7275-codeglance
This plugin allows you to preview 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).
This functionality is known from Sublime Text (which I can recommend, too).
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):
<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 project page: https://emmet.io/
Here I want to highlight some basic techniques how to navigate through your code. All functions can be found in Navigation menu. The keyboard shortcuts are wrote for Windows system so if you’re using different OS – just check it in the navigation menu. Using these features directly from keyboard will save you a lot of time.
Go to line (ctrl+l)
Truly self explanatory. Additionally you can specify column you want to jump. E.g. typing 3:5 will route you to 3rd line and 5th column.
Go to class (ctrl+o)
If you know your class names – use this to quickly jump to class definition. After typing any part of class name – you can see 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’s 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 line number. After doing that we can…
View bookmarks (ctrl+F3)
View and navigate through all defined bookmarks. Additionally snippet of the nearest code is presented. Very helpful.
Back/forward (ctrl+[ and ctrl+])
Bo 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 above but navigate only to places where any changes were made.
Go to 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 directory or opening selected file).
File structure (ctrl+F12)
Quick preview of current file structure. So all classes, methods, functions, variables – in one place, sorted. Good place to start when analysing new source file.
Next highlighted error (F2)
Go to next error found by PHPStorm. Great for fixing all syntax or code style issues in file.
You can find more in official PHPStorm documentation:
Simply duplicates content.
- After selecting part of the line – will copy and paste it after selection,
- If there is no selection – 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 recommend also 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 lets 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 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 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:
Hope you learned something new during reading this post. Maybe you have some neat tricks too? If so – share with us leaving a comment!