My most useful IntelliJ IDEA keyboard shortcuts

posted by Roberto Cortez on
tags: ,

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

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 + 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 SHIFT, you can unselect by context as well.

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.

IDEA Recent 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()
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 + N Go 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 + SPACE Smart 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 + 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.

Share with others!
  • Twitter
  • Facebook
  • LinkedIn
  • Google Plus
  • Reddit
  • Add to favorites
  • Email
  • RSS

Comments ( 13 )

  1. Replyivan_stefanov

    Great post, Roberto! :)

    You are IntelliJ IDEA veteran, that’s why you forgot about a shortcut that newbies like me tend to use very often: CTRL+SHIFT+A (I guess on MAC is CMD+SHIFT+A). It pops up a box, where you can enter the action you want to perform and when you press Enter, it does it. Kind of a meta shortcut 😉

    It’s very useful for learning shortcuts as well, because besides the action name, it also displays the shortcut to execute it.

    • ReplyRoberto Cortez

      Hi Ivan,

      Thank you. I didn’t forgot about that one, it’s just that I don’t use it very often :)

      But thank your for mentioning it!

    • Replyjnuc093

      yes it is the first userful shortcut key

    • Replymy dealz kreditkarte

      Thank you for writing that. Such references are excellent for people trying to get their head around the nature of ballroom. And I know how much time it can take to write such a piece too.I like also the way you point out when something is your opinion too. Some people are certain that they know it all – when really who does?Thanks again.

    • Replyhttp://www./

      Thanks so much for taking the time to mention my book and run the excerpt. One new update: Over the Top & Back Again: Hiking X the Alps just received the 2010 Book of the Year Bronze Award (travel essay category) from ForeWord Reviews at the American Library Association conference in New Orleans.For everyone who has gone digital, it has also just been released on Amazon Kindle (lighter to pack that way!). Happy Extremes![]

    • Replysupe app coins free

      Thanks for the K12b results of all samples from Aydin, Istanbul and Kayseri. I am wondering if you could also provide K12b results of all individuals and all reference populations in a large spreadsheet?

  2. Replykotseto

    Great post, I’ll come here often :)

    Recently in IDEA they added the double Shift (press Shift, then press Shift Again) – Search Everywhere feature. In case you do not search just for Java stuff its very useful. I use it every day.

    Other very useful shortcut that I also use very often is Ctrl (CMD) + F12 – it will navigate through current file – very useful wa to go to a method or variable – much faster than the usual Ctrl + F, type + Enter – just press Ctrl (CMD) + F12 and start typing

    • ReplyRoberto Cortez

      Hi kotseto,

      Thank you for your comment and for being a returning visitor :)

      Of course there are many others shortcuts, but I choose to include the ones I use the most. Ctrl / Cmd + F12 is probably right after these ones. I use it a lot as well. Double shift, not so much because I find it a bit slow without a SSD Disk and compared to the other Go To shortcuts.

      Anyway, it was great for you to add these here. Thanks again!

  3. Replyjax

    Hi,
    How can I subscribe for comments?

    • ReplyRoberto Cortez

      Hi, I’m not supporting it at the moment, but thanks for asking. I’ll try to add support in the following weeks.

  4. ReplyJeshan Babooa

    Hi Roberto,
    I understand that you didn’t mean this list to be exhaustive but may I add some which I think are quite cool? Others may find it useful.

    1. navigate between methods with alt+up/down: This makes it really easy to move across methods, especially in large files. I learnt this one from Trisha Gee.

    I’m also digging deep into the documentation and “hidden” features available in the keymaps.
    I found some goodies:

    2. Refactor this (ctrl+alt+shift+T) will show you various refactoring options. I consider this one a must have.

    3. I think recent changes (alt+shift+C) suits well with the ‘recently changed files’ as you mentioned.

    4. show usages (ctrl+alt+F7) to quickly navigate to the use of a symbol across files.

    A last pair which I wished people appreciate the value but which aren’t assigned shortcuts by default: split vertically/horizontally. This is very useful to reference a file while working on another. The thing which I like the most is that you can open several views of the same file if needed. This can be useful when you need to look at code in more than one place in file at the same time!

    • ReplyRoberto Cortez

      Hi Jeshan,

      Thank you very much for your comment.

      Yes, this is not an exhaustive list. The shortcuts you mentions are also very useful, but one thing I realised is that you usually have multiple ways to do accomplish things in IntelliJ. And the way you do it, depends a lot of your coding style.

      Let me give you an example: I usually don’t use ALT+Up or Down to navigate methods. I use CMD/CTLR + F12 to have a list of all methods in the class and then type to filter the method I want. Or CMD/CTRL + SHIFT + ALT + N to jump to any method in any class. You can also use Double SHIFT, but for some reason, I don’t use it as much, maybe because I was used to the other shortcuts before Double SHIFT being introduced.

      Cheers,
      Roberto

  5. ReplyLonnie

    If you are interested in topic: earn online wikihow minecraft – you should read about Bucksflooder first

Leave a reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>