Eclipse Productivity Shortcuts


Back in college, I used to be a notepad nazi, so as to say. I used to code all my giant programs solely in notepad (The most I upgraded to was to Textpad). And once I joined Google, I was apathetic to IDEs, so I just picked IntelliJ and went with it. Somewhere down the line, I attended a Testing and Refactoring workshop, and the only IDE available was Eclipse. And it was for a great reason.

While the focus of the workshop was testing and refactoring, what they did do, which I applaud them for, was they showed us some awesome shortcuts. And suddenly, I was doing these insane refactorings at the blink of the eye. It was then that I started searching for and learning every eclipse shortcut that would help me be more productive. And before I knew it, I was typing 6 words a minute and coding up 100 words a minute :) . And I loved it.

And so, today, I just wanted to share the best shortcuts that make life easier. And without further ado :

Ctrl + Space : One of the two most important keyboard shortcuts that eclipse offers. This one is probably commonly known for autocomplete in eclipse, but not many people know that it is also context sensitive. For example, hitting Ctrl + Space when you are in the middle of typing will show you all members and methods that begin with your text. But hitting Ctrl + Space when you have nothing typed shows you all members and properties available. But the real eclipse masters know that, hitting Ctrl + Space when you type in for or foreach will show you autocomplete options for generating a for loop or for each loop. And if you do it right after you assign something to a collection or a list, it will fill in the loop variables for the for each loop. Autocomplete after typing in test, will allow you to generate the skeleton of a JUnit test case method. Autocomplete after typing in new, generates you a skeleton for a new call, which you can tab through and fill in. So many more uses and use cases for Ctrl + Space that can be found. You can generate / override method signatures in child classes. Just use and abuse it, and you will learn so much.

Ctrl + 1 : If there is just one more shortcut you remember from this post, let it be this one. The other super awesome, context sensitive shortcut in Eclipse, which is basically Quick Fix. If you have an error in a line, Ctrl + 1 will show you potential options to fix it, like importing a class, or adding an argument to a method or fixing the method signature. If you just do a method call which returns something, then you can hit Ctrl + 1 and ask it to assign it to a new local or field variable. You can hit Ctrl + 1 on a parameter to a method and assign it to a field. Ctrl + 1 on a variable can allow you to inline it, and on an assignment, can allow you to split up the declaration and assignment, or convert it to a field, parameter, etc. It is, by far, The Most Awesome  Keyboard shortcut that you can know and use. Especially on errors!

Ctrl + F11 : Reruns the last run configuration that was executed. If you do TDD, then Alt + Shift + X, T followed by Ctrl + F11 is the most standard approach.

Ctrl + Shift + R : Shows the Open Resource dialog. Type to filter, and jump directly between classes. I love this shortcut, and use and abuse it!

Ctrl + Shift + O : Organizes Imports, and gets rid of unused imports.

Ctrl + O : Shows the methods and properties of a class. You can start typing to filter and hit enter to jump to a particular signature / type. Hitting Ctrl + O again toggles showing inherited members. Very useful for jumping between sections in a class, or finding that one method you want to get to.

Ctrl + T : Opens the Type Heirarchy. Shows all super classes as well as sub classes / implementing types in your class path. Very useful for jumping to an implementation class. Can be called from the class type, or even a method signature. Can toggle between Supertype and Subtype heirarchy if you hit Ctrl + T again. Again, you can type and filter once you are in this menu.

Ctrl + / : Comment / Uncomment code. Single or multiple lines, depending on what you have selected. Enuff said.

Alt + Shift + R : One of my most used shortcuts, Rename. It renames anything from variables to methods to even classes, renaming the class files if necessary. Also fixes all references to refer to it by the new name. Can sometimes break if there are compile errors, so watch out when you use it. You can also ask it to fix all textual references as well.

Alt + Shift + M : Extract Method. Super useful method to break up a larger method into smaller chunks. If the code block you have selected does not need to return too many types, and looks reasonable as a separate method, then pulls up  a prompt where you can basically edit the method signature, including return type, method name and order and type of parameters. Very useful

Alt + Shift + C : Only useful when the cursor is on a method signature, but this one allows you to refactor and change the method signature. This includes changing the return type, method name, and the parameters to the method, including order, and default values if you are introducing a new one. Automagically fixes all references to said method.

Alt + Shift + L : Once you have a expression selected (a method call, or whatever), then Alt + Shift + L extracts that to a local variable. It prompts you for the name of the variable, and automatically infers the type as best as it can. Extremely useful shortcut!

Alt + Shift + Up / Down : This one is a useful one. If you hit up, it selects the next biggest code block, down selects the next smallest. Useful in conjunction with refactoring shortcuts like extract local variable, extract method, etc. Useful to know.

Alt + Shift + T : Brings up the Refactor menu. Depending on the context, this will show options like Rename, Move, Extract Interfaces and classes, Change Method Signature, etc. Nice to know, but not one I use very often. The ones I do use have already been listed above.

Alt + Shift + S : Shows the Source menu. This includes menu options like Comment related, and the ever useful Override / Implement Methods, Generate Getters and Setters, and much more. Some of the menu options have direct shortcuts, but a lot of the generate commands don’t, so useful to know.

Alt + Shift + X : Pulls up the Run menu, and shows what key you have to press to run a particular type. Now I generally use this as Alt + Shift + X, followed by T, which basically executes a JUnit Test. Fastest way to run unit tests without leaving the comfort of your keyboard.

Alt + Up / Down : Moves a block of lines up or down. Rather than say, selecting, hitting Ctrl + X and then going to the place and pasting, why not just select all the lines, and use Alt + Up or Down to move them. Automatically handles indentation depending on the block. Very convenient

Ctrl + D :  Nice and Simple, deletes the current line the cursor is on. If you have selected multiple lines, then they are all blown away. Much faster than selecting a line and hitting delete.

UPDATE: Adding in some of the shortcuts that I forgot or were mentioned in the comments for easy finding

Ctrl + L : Jump to a Line number

Ctrl + Shift + T : Display available types. A better version of Ctrl + Shift + R if you are only looking for Java classes

Alt + Shift + Up / Down : Duplicate selected lines above or below. Easier than hitting Ctrl + C followed by Ctrl + V

Ctrl + Alt + H : This one, I didn’t know about. but pulls up the Call heirarchy, showing you all callers and users of the method under the cursor. Super useful, especially if you are refactoring.

Ctrl + Shift + L : Show the list of shortcuts. You can hit it again to go in and edit your shortcuts.

, , , , ,

  1. #1 by txxxxd on July 29, 2009 - 10:01 am

    Ctrl + Shift + T is a better version of Ctrl + Shift + R if you’re looking for a Java class.

    • #2 by Shyam on July 29, 2009 - 10:27 am

      Agreed, but I usually end up working with more than just java files, so since Ctrl + Shift + R finds everything, i stick with that.

  2. #3 by Mark on July 29, 2009 - 10:23 am

    Ctrl-F11 is broken since v3.3. Everytime I use it it tries to run a server, not the target at the top of the list.

    Ctrl-F6 is mapped to change edit windows. I remap it to Ctrl-Tab for quick and easy editor switching.

    Ctrl-, and Ctrl-. navigate through all Errors, Warnings, Todos, etc in the current editor.

    • #4 by Shyam on July 29, 2009 - 10:28 am

      Ctrl + F11 seems to work with JUnit tests, which is what I use it for mostly. Ctrl + Pg Down / Pg Up is also good to switch between tabs. You might wanna look at Ctrl + . (Dot), as it allows you to jump to the next warning / error in the editor as well.

  3. #5 by Raju on July 29, 2009 - 10:23 am

    Good list. I use most of those, but the Alt-Shirt-Up/Down is really nice. Thank you for that. Two more that I find useful –

    Ctrl + L – Brings up a dialog for a line number to navigate to
    Ctrl + Shift + L – Brings up a popup of shortcuts (Handy especially when new to learning the shortcuts)
    Ctrl + Shift + Up/Down – Moves the caret to the previous or next method.

    Great list, thanks.

    • #6 by Shyam on July 29, 2009 - 10:29 am

      Yeah, Ctrl + L is a life saver, for sure. There are quite a lot more, but the ones that I use extensively are the only ones I listed, though I can’t believe i forgot line number jump. Thanks

  4. #7 by Mike on July 29, 2009 - 4:07 pm

    I’ve used many of these, but some were new. I’m sure I’m going to use Alt +Up/Down in the next few days for sure…moving lines up or down is a very common operation for me. It’s good to have all of them in a single list. Thanks for compiling this!

  5. #8 by Russ on July 30, 2009 - 11:15 pm

    Life wouldn’t be the same without Ctrl + Alt + H. Opens the Call Hierarchy when the cursor is on a method symbol. Finds readers and writers when on a field symbol. Finds all callers of all contructors when on a class symbol. And the call hierarchy can be expanded at any node, so it’s often much more useful than a search.

    Nice list!

  6. #9 by Arun Srinivasan on August 3, 2009 - 11:35 pm

    Good one, can you also add the new ones from comments in your post?

  7. #10 by Sam Brannen on August 6, 2009 - 2:47 am

    Instead of hitting the cumbersome key combination “Alt + Shift + X, followed by T” to run a JUnit test, I always go to Preferences / General / Keys and configure “Run JUnit Test” to Ctrl + J and “Rerun JUnit Test” to Ctrl + Shift + J. That saves a lot of time. ;)

    – Sam

    p.s. note that those two “J” key bindings are already assigned to “Incremental Find” and “Incremental Find Reverse” by default, but I configure Ctrl + F to be “Incremental” via the checkbox anyway. So I just unbind these “J” bindings before assigning them to JUnit.

  8. #11 by Vijay K on August 15, 2009 - 4:33 pm

    Also found useful -
    Ctrl+Q – takes you to the last edit location.
    Ctrl+Shift+G – searches for where the selected method is called.

  9. #12 by Steven Sproat on June 13, 2010 - 1:22 pm

    Ctrl+Space mid-typing also inspects your open projects/classes Eclipse knows about on your classpath, and will auto-import these for you. Works great with Spring annotations.

  10. #13 by Gwyn Goolden on November 20, 2010 - 8:58 pm

    The website author has a specified ability to describe truly really beneficial subjects. Reading this world-wide-web web site is genuinely enjoyable and you’ll find absolutely a lot of great comments. In any circumstance, it was a pleasure to invest time in your website internet site and go through the thrilling report.

  11. #14 by Javin Paul on January 7, 2011 - 8:29 am

    here is my list of useful eclipse shortcut I would rather say very useful and practical eclipse shortcut :)

  12. #15 by Maricela Olson on May 26, 2011 - 8:24 am

    I frequently use Eclipse. And some of the shortcuts that I use are the following: ctrl+1 = quick fix, hold shift and move = from-to selector, ctrl+d and ctrl+alt+down or up = delete and duplicate current row, ctrl+shift+fn+0 = collapse all, home,shift+end or alt+down,alt+up = select current row, etc. However, I do not use shortcuts like ctrl+shift+f – auto format ) and ( ctrl+shift+o – auto organize imports ).

  13. #16 by Atul_shukla on November 2, 2011 - 8:12 pm

    Nice One!!

    Ctrl+shift+L (For all shortcuts keys display in Eclipse)

(will not be published)