My most useful IntelliJ IDEA keyboard shortcuts
Are you looking for ways to be more productive? It shouldn’t be a secret that performing actions using the keyboard instead of the mouse will save you time. If you think only about a single action it’s not a big deal. What if you use the same action multiple times a day? If you add up all these actions, they can have a great impact on your productivity.
I’m more or less used to drive most of my actions with keyboard shortcuts. When I was younger, I played semi-professionally Real Time Strategy computer games, including Starcraft and Warcraft III. Starcraft, popularized the term APM (Actions per Minute), which counted the number of actions that a player performed per minute. By using tools, it was possible to record APMs and tell if players were using mouse actions or a keyboard and mouse action combination. Usually, players with a keyboard and mouse combination gameplay had a better chance of winning games than the one that just clicked.
So, what does this have to do with code and IntelliJ? Well, I believe that you can increase your code development productivity by learning and using the keyboard shortcuts to perform the desired actions. You can check the keyboard shortcuts on IntelliJ and you can also check the Productivity Guide which monitors your most used actions. This information is very useful, but it may be a little difficult to change your habits right away. To help you with this, I will describe my most used shortcuts in IntelliJ. You can start familiarize yourself with these and slowly introduce additional shortcuts.
Shortcut | Description |
---|---|
CTRL + W / CMD + W | Syntax Aware Selection This allows you to select code with context. Awesome when you need to select large blocks or just specific parts of a piece of code. If you have this code: files.getFiles().forEach(auctionFile -> createAuctionFile(realm, auctionFile)); And place the cursor in the auctionFile and use the shortcut, it will select auctionFile. Press it again and the selection will expand to auctionFile -> createAuctionFile(realm, auctionFile). If you press it again, now the selection will expand to files.getFiles().forEach(auctionFile -> createAuctionFile(realm, auctionFile)). Pressing a final time, you get the full piece of code selected. If you combine it with |
CTRL + E / CMD + E | Recent Viewed Files This will show you a popup with all the recent files that you have opened in the IDE. If you start typing, you can filter the files. |
CTRL + SHIFT + E / CMD + SHIFT + E | Recent Edited Files Same as Recent Viewed Files, but only shows you the files that you’ve actually changed. |
CTRL + B / CMD + B | Go to Declaration If you place the cursor in a class, method or variable and use the shortcut you will immediately jump to the declaration of the element. |
CTRL + SHIFT + ENTER / CMD + SHIFT + ENTER | Complete Statement This will try to complete your current statement. How? By adding curly braces, or semicolon and line change. For instance, if you have the following statement: System.out.print() Another example: |
CTRL + N / CMD + N | Go to Class This one allows you to search by name for a Java file in your project. If you combine it with |
CTRL + SHIFT + SPACE / CMD + SHIFT + SPACE | Smart Type Completion I didn’t mention it before, but I guess you are familiar with auto complete via |
CTRL + ALT + ← / CMD + ALT + ← | Navigate Back This allows you to navigate back like a browser action. It remembers where your cursor was positioned and navigates back even to other files. |
CTRL + ALT + → / CMD + ALT + → | Navigate Forward It’s like Navigate Back but goes Forward. Duh! |
CTRL + SHIFT + F7 / CMD + SHIFT + F7 | Highlight Usages Place the cursor in a element and after pressing the cursor the IDE will highlight all the occurrences of the selected element. |
There are many more keyboard shortcuts. Almost every action has an equivalent shortcut. It’s hard to learn them all, it takes time and practice. I still learn new things every week, and if for some reason I don’t code as much for a few days, I forget about the new shortcuts I’ve learned. It’s practice, practice, practice! Try to learn a few and master them instead of trying to do everything in one go. It’s easier!
An IntelliJ plugin exists to tell you with shortcuts you should use if you use the mouse. Its Key Promoter, but unfortunately it seems it’s not maintained anymore. Maybe I can update it for the latests IntelliJ versions. I would also like to see in the Productivity Guide a count of actions performed by shortcuts or mouse. If I find some free time, maybe I can do it too.
Hope you enjoyed it.
Reference: | My most useful IntelliJ IDEA keyboard shortcuts from our JCG partner Roberto Cortez at the Roberto Cortez Java Blog blog. |
One keyboard shortcut that I use most is,
ALT + F7: Find usages