Sunday, April 29, 2012

Top 10 Eclipse Shortcuts With Screen Shots!

Hmm.... You have the ubiquitous eclipse staring at you with an overwhelming array of menus ,tabs and panels. Knowing keyboard shortcuts is going to make your life a lot easier and development faster.

I am writing this article after learning them in the industry for 2 years and then teaching some of the tips to my friends while pursuing my MTech. Beginners are always pleasantly surprised when they find out how quick things can be when using shortcuts.

The Java Project we will be using for our tutorial can be downloaded here
The use of the word cursor means the keyboard cursor that blinks not the mouse cursor.

The following UML diagram explains our classes we will be working on.(In case you are curious how I created the diagram, I used the software dia)

Animal Kingdom-Class Diagram

Now to get our Hands dirty...

1. Ctrl + Space (Content Assist / Auto Complete)  :
    Suppose you want to print the tiger's weight, then after typing bengalTiger. press
    Ctrl+Space, you will be able to see the possible methods that can be called and the attributes that
    can be accessed. You can use your arrow keys to scroll down to the method getWeight and
    press enter. The following screenshot will make it clear.

2. Ctrl + Shift + R (Open Resource : Suppose you just have the tab open in the editor and want to take a look at the class, then
     instead  of using your mouse to go all the way to the package exporer and clicking on the file,
     press Ctrl + Shift + R - this opens a new window and start typing An , you will see a list of all
     classes that start with the letters "An" in the workspace. Again use arrow keys to navigate and
     chose the file you want to open.
     Extremely helpful when you are working with multiple projects and hundreds of files.

3. Ctrl + L (Go to Line) :
    Instead of using the arrow-keys to scroll up and down to go to a particular line number, pressing
    Ctrl + L will open a window with a text box to enter the line number you want the cursor to be
    Helpful when you have large piece of code in a single file.


3. Ctrl + O (Quick Outline) :
    You are now in the Animal class and want to have a quick view of the class features-its methods
    and attributes etc.. Ctrl+O opens a window which shows you just that!You can type to zero in
    on the method/attribute you want to see and pressing Enter takes you to its definition.
    Helpful when looking for a specific method name in a large class

4. Ctrl + Q (Last Edit Location):
      My personal favorite! This shortcut saves you a lot of frustration when you want to continue
      from where you left off coding and went searching for some information in eclipse.
      Its hard to put a screenshot for this, but try doing this. Add a statement in the, and
      open Now press Ctrl+Q, this will place the cursor in the location you last edited.

5. Ctrl + E (Quick Switch Editor):
You have a lot of tabs open in the editor and want to open a file which you know is one of the tabs.
    Ctrl+E shows a drop down listing all the current open files in the editor.Again, use the arrow keys
    and select the file you want to open. Also you can type the name of the file and press Enter to
    open the file.

6. Ctrl + W (Close Current Tab):
    The name says it all...Just press Ctrl + W and the current tab in the editor closes.When there are
    a lot of open windows overwhelming you, Ctrl + Shift +W closes all of them.

7. Ctrl + M (Maximize/Minimize):
    The program just ran and you want to see the console tab in full view of the widow.Click on the
    console tab and press Ctrl + M. You can view it in the whole window.Repeat to minimize to the
    original position.

8. Ctrl + D (Delete Line):     When there's a line that needs to be swiftly deleted, then place the cursor anywhere in the line,     then press Ctrl + D.

9. Ctrl + T (Quick Hierarchy):
Open Place the cursor over Tiger. Press Ctrl+T. The small window
    that opened up shows the inheritance hierarchy.

10. F3 (Open Declaration):
      Many times you would want to see the declaration/definition of a class or a method.Say you
      wanted to see the Tiger class in detail. Place the cursor on the word Tiger in and
      press F3, the file opens.

Thats it for now! Make sure you also check out - Ctrl + F11, F11,  Ctrl+Shift+L and Ctrl+H.

Thanks for reading :) Please post comments...


  1. Hi,
    The post seems good..all useful shortcuts at one place. I really like F3 shortcut but how would lgo back to the file that i came from? Because that is much needed

    1. Thanks for the compliments.. For that the short cut is Alt + left-arrow.