Mastering your IntelliJ IDEA: 7 Tricks to increase your productivity
An integrated development environment (IDE) is a tool developers use daily, so we should master it.
We usually use some shortcuts daily, like CTRL + C and CTRL + V, but we can also use many more, to do many things, like formatting the code, identifying errors, and also using the IDE to suggest solutions for these errors.
All the Keyboards shared here can be used with Windows & Linux, at the end of this article you can have a look at a cheat sheet with the reference for Mac, and also other shortcuts.
Let’s talk about 7 tricks that would help us increase our productivity during our daily activities.
1. Show intention actions and quick-fixes — Alt + Enter
This is probably one of the most useful shortcuts we can use. This shortcut will provide us with some hints that we can apply, for example:
Flip the if statement, static import, create a variable, and more. We can use it using the Alt + Enter shortcut.
When it's red, yellow, blue or gray, Alt-Enter will save your day.
- Victor Rentea
2. Duplicate current line — Ctrl + D
When writing code, it's common to need to duplicate a line. However, instead of writing everything twice or using Ctrl+C and Ctrl+V, it's more efficient to simply duplicate the line.
We can do that using the shortcut Ctrl + D
3. Delete line at caret — Ctrl + Y
And how about deleting one line, there are many ways, we can select the entire line and then remove it, or use backspace many times, please, don’t tell me you do that 😅
We can do this smartly, only using the shortcut Ctrl + Y
4. Extend selection — Ctrl + W
Extend selection is a very useful thing that can help us to select one or many blocks of code. For example, let’s say we want to select the entire line, or the entire if statement block.
We can do that using the shortcut CTRL + W
I do recommend testing it out, there will be probably one situation in which you will need to use it, and selecting with a mousepad could be a nightmare.
5. Shrink selection Ctrl + Shift + W
As we saw before, we can extend the selection, and also shrink the selection. They both do things similarly but with opposite behaviour.
We can do that using the shortcut CTRL + Shift + W
6. Generate code — Alt + Insert
Have you ever needed to create the getters and setters manually, or maybe the constructor, or equals and hash code?
How do you create the test for your class? Do you go to the test folder and create a new file?
Well, if you answer yes to any of those questions, I have good news: a shortcut can help you generate all this boilerplate code.
We can do that using the shortcut Alt + Insert and then select what we want to generate.
7. Select multiple lines — Ctrl + Alt + Shift + Click
Last, but not least, this is something that can help you a lot to increase your productivity in some activities. How many times do you need to change many lines with the same behaviour?
For example, adding a break line at the end of the lines or a comma.
In this article Mastering your IntelliJ IDEA: 6 Tricks to help with Refactoring, I’ve shown how to use the Select All Occurrences Hotkey action to select all the occurrences, it is very useful, but it doesn’t fit all the use cases.
We can use the shortcut Ctrl + Alt + Shift + Click to select many lines.
And because we get here, I’m going to share another way to select many lines. You can do that using the mouse scroll, you only need to press it and scroll down or up 😊
Conclusion
These are only a few shortcuts that can help a lot with our daily activities. I highly recommend you to use them. It can be hard in the beginning because you are not used to it, but the key is consistency.
I hope these shortcuts can help you, and if you know any other shortcuts that you like to use, share them here in the comments 😁😁
Access this cheat sheet to see most of the shortcuts you can use with IntelliJ: IntelliJ Shortcuts Cheat Sheet.