Switching to and customizing IntelliJ



Hello! Read on if you decided to switch to IntelliJ, set it up, make it comfortable and learn how to be more productive with it. This post covers some settings and custom shortcuts.



The first things that annoyed me were the popups in the top-right corner. To disable some of them:
'Event log' on the bottom-right (or Speech bubble icon) -> Settings. Disabling the balloons doesn't hide the notifications from the event log, so you can check that if you need to.

Next up is removing the default comment generated at the top of a new class file.
File -> Settings -> Editor -> File and Code Templates -> 'Includes' tab -> File header -> the comment is on the right -> delete it.
If you would like to use this feature make sure to print the date in a less ambiguous format.

Another one is the vertical line in the editor that is set to 120 chars per line by default. To change the line limit:
File -> Settings -> Editor -> Code Style -> Right margin columns.
The Google Java Style Guide https://google.github.io/styleguide/javaguide.html recommends a column limit of 100 chars.

Speaking of style, it would be nice to add one. Import a xml file containing the rules this way:
Download intellij-java-google-style.xml from https://github.com/google/styleguide
File -> Settings -> Editor -> Code Style -> Manage -> Import the file.
The rules will be applied to your code when you reformat, default shortcut: Ctrl Alt L.



Ok hotkeys. Some are very hard to reach, hard to learn or conflict with something else. Here are some recommendations how to make your life easier. You don't need to remove the old shortcut, so if someone else wants to use your Idea they can still use the default keys they know. Go to File -> Settings -> Keymap and find the ones you need to change, then click on them and select 'Add keyboard shortcut'. All of the recommended ones are unused and should be added as alternatives. For each entry I have specified: the name of the command, the default shortcut, the suggested one and an explanation.

Rename: default - Shift F6, suggested - Alt R. This default key is famous for being so hard to reach. Usage of rename should be encouraged as naming things is one of the hardest tasks in programming. Remember it as R stands for rename.

Find usage: default - Alt F7, suggested - rightAlt U. Shows you where a method/variable is used. One hand - easy. Associate U with usage.

Surround with...: default - Ctrl Alt T, suggested - Alt T. Surrounds the selected code with if/elseif/while/for/try... etc. Some Linux distros have the terminal shortcut bound to Ctrl Alt T so that causes a conflict. Even if you don't care about that the alternative is still 1 less key to press.

Delete line at caret: default - Ctrl Y, suggested - Alt X. In Eclipse it was easy to Ctrl D with one hand, but Ctrl Y requires both hands. The Alt and X keys are next to each other and this one is very easy to press. The X can be associated with double-crossing something.

Run: default - Alt Shift F10, suggested - Alt P. Usefulness depends on how often you run the project. P as in play for the green arrow icon. An even easier variant is Alt E as in execute.



Next, I have compiled a list of the more notable shortcuts. Some are based on people's opinion from Stackoverflow. A more complete list can be found at:
https://resources.jetbrains.com/assets/products/intellij-idea/IntelliJIDEA_ReferenceCard.pdf
and https://www.shortcutworld.com/en/win/IntelliJ.html
and you can always check the key for actions by pressing Ctrl Alt A in Idea.

Go to declaration => Ctrl B
Open class => Ctrl N
Rename refactor  => Alt R; Shift F6
Refactor variable from expression => Ctrl Alt V
Extract method => Ctrl Alt M
Smart completion => Ctrl Shift Space
Cyclic expand word => Alt forwardslash
Complete statement => Ctrl Shift Enter
Reformat, Checkstyle, fix imports => Ctrl Alt L
Find in whole project => Ctrl Shift F
Switch tabs => Ctrl Tab
Quick fix/intentions => Alt Enter
Smart template => iter/psf/thr Tab
Find Usage => rightAlt U; Alt F7
Brief info => Ctrl mouseover
Duplicate => Ctrl D
New line below => Shift Enter
New line above => Ctrl Alt Enter
Expanding select => Ctrl W
Delete to word start => Ctrl Backspace
Delete line => Alt X; Ctrl Y
Paste previous copies => Ctrl Shift V
JavaDoc => Ctrl Q
Run => Alt P; Alt Shift F10
Go to previous/next method => Alt Up/Down
Go back to code => Ctrl Alt Left
Go to next error => F2
Parameter info in method call => Ctrl P
Show TODO list => Alt 6
Bring up the file/class/method quicksearch => Shift Shift
Open the switcher => Ctrl Tab
Hide active window => Shift Escape

If you think a shortcut or setting you often use is missing - tell me!

Comments

Popular Posts