Thursday, April 8, 2010

Helpful IntelliJ IDEA Shortcuts

IntelliJ IDEA Shortcuts

After settling in at the new gig, the IDE of choice for my team is IntelliJ IDEA. I've been using Eclipse for many many years now so there has been growing pains because of the simple fact that I was extremely familiar with all the ins-and-outs of Eclipse and the shortcuts they offered. After a month or so of using IntelliJ, I'm getting more comfortable with it. I found myself writing these notes on a scratch pad and figured I post an entry on it before I spill hot coffee all over my notepad and start crying like a little baby. Without further ado, heres my list:

Various Fixes - alt+enter

This tool is equivalent to ctrl+1 in Eclipse and acts as a kind of quick fix tool for you. You'll probably use it the most for the following:
  1. Adding import declarations.
  2. If code is highlighted yellow, IntelliJ is suggesting that you can possibly write your code in a more efficient manner. Simply double click the piece of code and hit alt+enter. This will give you some refactoring options.
Code Complete - ctrl+shift+enter

This nifty shortcut will complete syntactical code for you such as closing braces during a method declaration, or by typing "if" then hitting ctrl+shift+enter will close add the parentheses for evaluation as well as the open and close brackets for the if block. Probably does a lot more but that's what I use this for the most.

Dumb Auto Complete - ctrl+space

This "dumb" autocomplete usually appears automatically after you type the "." after an object variable. For instance assume someArrayList is of type ArrayList and when typing "someArrayList.", suggestions are offered based off of that object appear.

Smart Auto Complete - ctrl+shift+space

This is really useful one. It acts similar to the dumb complete key but there's is a crucial difference. This shortcut narrows suggested methods down by type. For instance, let's take our "someArrayList." example again. Shortly after the period you will get suggested methods based off of the entire ArrayList object. This is the the expected "dumb" auto complete view as I explained in the previous shortcut. However when you instead press ctrl+shift+space, IntelliJ will actually filter those methods based on the type in which the return is being assigned to. So if we were create a integer variable to store the size of someArrayList like so "int size = someArrayList.", smart complete will only expose methods off of the ArrayList object which will only return an int value like size(), hashCode(), lastIndexOf() and indexOf()... Very useful!

View Java Docs - highlight method or class+ctrl+q

Nuff' said.

Highlight instances of a term - highlight item+ctrl+shift+f7

Nifty shortcut that will search, locate and highlight all the matching terms you've selected within a file.

Refactor a piece of code - shift+f6

Highlight code and shift+f6 to view suggested refactoring options.

Extract expression to a method - ctrl+alt+m

There are times where you find yourself writing inline, procedural code that should be in its own method but you just don't get around to extracting it because you're lazy. This awesome shortcut provides a very simple way to highlight code, turn it into a method update your references to it. Just like Geico says, "so easy a caveman could do it". Do it!

Select word the cursor is currently on - ctrl+w

When you really don't feel like using your mouse... geek.

Cycle through open editors - ctrl+left arrow or ctrl+right arrow

Nuff' said.

Cycle through methods in a file -ctrl+up arrow or ctrl+down arrow

Nuff' said.

Once debug servers are setup to launch debug shift+f9+enter

Launches debug server.

Terminate the debug server - ctrl+f2

Nuff' said.

And finally, the usual suspects...
Search for a Java Class - ctrl+n
Search for file in project - ctrl+shift+n
Search for term within project - ctrl+shift+f
Comment out code - highlight lines+ctrl+/

There you have it. Hopefully this can help guide IntelliJ noobs like myself in the right direction. I'm still feeling my way through this tool so if anyone has any other useful tips for IntelliJ, please post a comment. I'd love to hear them!



Jamie Krug said...

Hey Micky, good stuff. I just stumbled upon this while looking for something else IntelliJ IDEA related :) I'll also mention that the Ctrl+W can be repeated to expand out and intelligently select stuff, like word/variable, then parentheses, then entire if/function/whatever block--very cool! And Ctrl+Shift+W can be used to backtrack through selection blocks.

I've also found it useful to scroll through the Tips (under Help menu) or check out this Refcardz.


Micky Dionisio said...


Thanks for the awesome tips. Just tried out ctrl+w and ctrl+shift+w. It sure beats ctrl+shift+arrows keys. Thanks for the tips!