Compose code sonatas. Become the Chopin of your keyboard.



keyboard-shortcuts-ide

During pair coding with my fellow Java developers, I’ve noticed that some of them are not familiar with some useful features of IDE. It led me to the idea of writing a series of blog posts about some interesting functionalities/plugins that Intellij Idea provides.

In the future, I will provide you some keyboard shortcuts to navigate through projects.

Issue suggestions

Do you have some red (or yellow) underlined parts in the code? Focus cursor on one of them and press Alt+Enter and see IDE’s suggestions how to fix the issue. To iterate over the issues just use F2.

keyboard-shortcuts-alt-enter

Code generation

Do you want to get rid of manual implementation of constructors, getters, setters, toString, equals and hashCode? You can use automatic generation of the code – Alt+Insert.

keyboard-shortcuts-alt-insert

To extract some part of the code to method – use Ctrl+Alt+M.

keyboard-shortcuts-ctrl-alt-m

Similary you can do this for focused value to extract it to variable using Ctrl+Alt+V, or to constant using Ctrl+Alt+C.

keyboard-shortcuts-ctrl-alt-c

Magic selection

Did you know that you don’t need to manually select the strings, or some grouped parts of the code by a mouse, or arrows? There is a quite simple shortcut to select string, method name, field name or any other part of the code. Just use Ctrl+W to expand the selection, or Ctrl+Shift+W to narrow.

keyboard-shortcuts-ctrl-w

Similar lines

Sometimes you need to write multiple similar lines and pass different parameters. Why write them multiple times? Write the code once and use Ctrl+d to duplicate it. If you need to edit multiple lines use Ctrl+Ctrl(hold)+Arrow.

keyboard-shortcuts-ctrl-ctrl-arrow

Renaming

Instead of using search-replace – focus cursor on variable/constant/class/method and press Shift+F6.

keyboard-shortcuts-shift-f6

Tests generation

Instead of creating manually test classes you can use the shortcut Ctrl+Shift+T.

keyboard-shortcuts-ctrl-shift-t

Formating and cleaning

Formatting and cleaning. If you have a problem with organisation of the code you can use Ctrl+Alt+L to format the code. If you want to organize the imports use Ctrl+Alt+O, to execute all the formatting features just use Ctrl+Shift+Alt+T.

Also read: Know your IDE: IntelliJ IDEA (part 2) – Navigate Through the Project With Use of Keyboard.

Q: How can I fix issues in my code?

To fix issues in your code, focus the cursor on one of the red (or yellow) underlined parts and press Alt+Enter to see the IDE’s suggestions for how to fix the issue. To iterate over the issues, use the F2 shortcut.

Q: How can I duplicate lines of code?

To duplicate lines of code, use the Ctrl+D shortcut. To edit multiple lines, use the Ctrl+Ctrl(hold)+Arrow shortcut.

Q: How can I format and clean my code?

To format your code, use the Ctrl+Alt+L shortcut. To organize imports, use the Ctrl+Alt+O shortcut. To execute all formatting features, use the Ctrl+Shift+Alt+T shortcut.

Q: How can I extract parts of my code?

To extract a part of code to a method, use the Ctrl+Alt+M shortcut. Similarly, you can use Ctrl+Alt+V to extract a focused value to a variable or Ctrl+Alt+C to extract it to a constant.

keybord shortcuts IDE

5/5 - (4 votes)