IntelliJ IDEA is a wonderful piece of software.
And that’s all I’m going to say; I won’t run comparisons against other popular IDEs, because that’s a subject for another day. Today, I want to talk about sharpening your skills with IDEA.
We all know that shortcuts improve our productivity. Here are the ones I find most valuable:
- CTRL-W and CTRL-SHIFT-W: Select progressively greater / lesser levels of code
- CTRL-ALT-V: Introduce Variable. See also Introduce Field / Constant
- type “iter” TAB: Java 5 style for loop Live Template. See sections below for more info on this
- ALT-LEFT and ALT-RIGHT: View previous / next tab.
- CTRL-ALT-LEFT and CTRL-ALT-RIGHT: Back / Forward Tab (in history).
- CTRL-N and CTRL-SHIFT-N: Find Class and Find File.
- ALT-F12: Show class outline (press again to also show Inherited members).
- CTRL-D: Duplicate Line.
- F2 and SHIFT-F2: Go to next / previous error (or warning).
- ALT-INSERT: Create new file popup.
- CTRL-SHIFT-F: Find in path.
- CTRL-ALT-T: Show list of Live Templates.
- ALT-ENTER: Show Intentions (see below for more info)
Live Templates are snippets of code you can insert in and around pieces of code. The most common one would probably be “Surround with If”, which takes the highlighted code and surrounds it with an If statement. What’s more, it formats the code correctly so you needn’t worry about tab spacing.
To create you’re own templates, I would recommend you take a look at this Jetbrains blog post describing how to create a null-check template.
You can create a shortcut to open a popup of commonly used items of your choosing. Within Preferences, go to Quick Lists to define a new list, and then Key Intentions to create a shortcut for that list. As an example:
Intentions can be used to perform common actions, or solve problems with your code. Hitting ALT-ENTER over a valid piece of code will give you common actions. Doing the same over an error will give some suggestions such as:
- Migrate Type
- Cast expression
- Import unknown symbol