Software Development

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.
 
 
 
 
 
 
 
starcraft-apm.gif

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.

ShortcutDescription
CTRL + W / CMD + WSyntax 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 SHIFT, you can unselect by context as well.

CTRL + E / CMD + ERecent 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.

idea-recent-files

CTRL + SHIFT + E / CMD + SHIFT + ERecent Edited Files

Same as Recent Viewed Files, but only shows you the files that you’ve actually changed.

CTRL + B / CMD + BGo 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 + ENTERComplete 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()
Press the shortcut once to add an ending semi-colon. Press it again to add a new line and to position the cursor aligned with the last line.

Another example:
if (condition == true)
Press the shortcut to add opening and closing curly braces, and place the cursor inside the if body with additional indentation.

CTRL + N / CMD + NGo to Class

This one allows you to search by name for a Java file in your project. If you combine it with SHIFT, it searches any file. Adding ALT on top of that it searches for symbols. In the search area, you can use CamelHumps (type the capital letters only of the class name) notation to filter files.

idea-go-to-class

CTRL + SHIFT + SPACE / CMD + SHIFT + SPACESmart Type Completion

I didn’t mention it before, but I guess you are familiar with auto complete via CTRL + SPACE or CMD + SPACE. If you add a SHIFT you get the smart completion. This means that the IDE will try to match expected types that suit the current context and filter all the other options.

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 + F7Highlight 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.

 

Roberto Cortez

My name is Roberto Cortez and I was born in Venezuela, but I have spent most of my life in Coimbra – Portugal, where I currently live. I am a professional Java Developer working in the software development industry, with more than 8 years of experience in business areas like Finance, Insurance and Government. I work with many Java based technologies like JavaEE, Spring, Hibernate, GWT, JBoss AS and Maven just to name a few, always relying on my favorite IDE: IntelliJ IDEA.Most recently, I became a Freelancer / Independent Contractor. My new position is making me travel around the world (an old dream) to customers, but also to attend Java conferences. The direct contact with the Java community made me want to become an active member in the community itself. For that reason, I have created the Coimbra Java User Group, started to contribute to Open Source on Github and launched my own blog (www.radcortez.com), so I can share some of the knowledge that I gained over the years.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Halil Karakose
9 years ago

One keyboard shortcut that I use most is,

ALT + F7: Find usages

Back to top button