IntelliJ IDEA, by far, is the most productive and beautiful IDE out there for Java development. It features so many shortcuts and useful utilities, that I bet even the creators would have forgotten. These IntelliJ IDEA shortcuts can skyrocket your productivity while coding. To be honest, you don’t need to learn every shortcut, only a handful of them are used daily, and the following commands are even more common. These select few are enough for the everyday life of a programmer.
The list consists of both the Windows and the Mac commands.
This post is an addition to our post series to improve your productivity through IDEs. We already have written posts around it. You can learn about the Eclipse shortcuts in Eclipse IDE Shortcuts to Skyrocket Your Productivity.
Productivity can be improved with the plugins. You can find all the latest IDEs and their must-have plugins on, Extensions every Programmer needs for their IDE. We discussed these for IntelliJ IDEA, Eclipse IDE and VSCode. Please do check them out.
So let just jump right into it. But before prepare your cup of tea to sip and learn.
Fix the Error: Alt + Enter
Can not compile your code? Is the editor showing that dangerous wavy red line you are really scared of? No worries. Just call the IDE emergency helpline number and they will tell you what is wrong in there, and even provides the solution(s), sometimes. No, you don’t have to press 911, just
Alt + Enter. it will show you a list of the problem(s) and sometimes the solution(s) as well, right under the nose of the code or that red line of death. This one from the list of IntelliJ IDEA shortcuts you will be using more often than others.
Add Line Comment : Ctrl + / or ⌘ /
God, I hate comments, but only when, I, have to write it, otherwise I am fine with it. Just write the story of the code, which you probably won’t update even after 100 changes are done and not a single word is true in the comment, and press
⌘ / for Mac, or
Ctrl + / on windows. It will make it a line comment i.e adds
// in front of the line. if it already was a comment, then it reverses the effect to uncomment and removes
//. You can select the multiple lines and press the shortcut and it will do the same for all the lines.
Search Everywhere: Double Shift
Do you know the Magic Lamp of Aladin? When rubbed a Genie comes out of it and says, “Your wish is my command, O Master”, and you tell him your wishes. This command is similar to the magic lamp but instead of rubbing, you press it,
Double Shift that is. It opens a window, saying, Search everywhere (O Master). Type what you are looking for, in the IDE of course. It will give you any match for your input text such as Action, File, Text within a file, short cuts, and many more. This one from the list of IntelliJ IDEA shortcuts is like the one-stop solution for all your query.
Reformat the Code: Ctrl+Alt+L or ⌥⌘L
Did you know, that in the life span of the code, reading takes a lot of share than writing? And nobody wants to read a love letter with bad handwriting, do they? While writing the code, one must pay attention to indentions (python did a very good job with this), how the spacings are between the elements of syntax, is it readable or not, and if the style matches with the other parts of the code.
Fear not, just press the
Ctrl+Alt+L on windows or
⌥ ⌘ L on mac to reformat your code. It reformats the code to correct the above-mentioned features. You can change the format in the setting if don’t like the default one.
Rename: Shift + F6
You did a typo? The name of a variable just doesn’t quite match up with the value it holds? This method is being used in countless other classes but you want to rename it without breaking anything? Don’t worry. Introducing, Rename Anything. Just select the FIle, variable, class, or method you want to rename and press
Shift + F6 and replace it with the other word or fix some typo. This will reflect every corner of your code and don’t need to manually change every occurrence of it by yourself.
Generate code: Alt + Ins or ⌘+N or ⌃+Enter
Do you know what boilerplate code is? That’s something that doesn’t require that much of a brain strain and is very repetitive in nature. But you still have to do it such as getters and setters for the class level fields, constructor, or toString and many other things. it’s a common code and that be generated by your precious IDE for you. Just press
Alt + Ins or
⌃+Enter. You save a lot of time.
Next Error Please: F2
There are so many errors. Finding each red line will take more time than debugging them. I will tell you a secret, just press
F2, there will be little movement in your editor and what will you see is that your cursor is now pointing at the next error line. It’s like that ring bell in the shops to call out the next customer.
Short-Cutting the Post: Not a shortcut
As I said, there are countless other short cuts in the IntelliJ IDEA, but these were the most common and easy to remember shortcuts you should know. These 7 shortcuts are enough to make you write code like a pro. But you should go beyond and learn as many shortcuts as possible. So, how many shortcuts you should learn for maximum productivity and be a pro coder?
You should be able to code without touching the mouse.
Check out another post on Eclipse IDE Shortcuts to Skyrocket Your Productivity
That’s it guys for this post. Tell me if these shortcuts are enough or you would like to add more or replace a shortcut in the list with another shortcut. You can check my other post on best practices to boost your performance as well. Check out the project on GitHub. See you at your next tea time.