Eclipse - Most important and frequently used eclipse shortcuts



Idea behind writing this java eclipse tutorial came from my personal experience because correct usage of eclipse keyboard shortcuts expedite development. In this article I’ll be posting most important frequently used eclipse keyboard shortcuts.



Ctrl + Shift + R  - search resource like java class, interface, xml, jsp, text, config, property and log files etc.
This important Eclipse keyboard shortcut search resource like java class, interface, xml, jsp, text, config, property and log files etc.
It allows you to do wildcard search using * as well.

Ctrl + Shift + O - Organize imports (missing and unused imports)
This eclipse keyboard shortcut helps in importing missing import statements and removes all the unused imports.


Ctrl + Shift + T - Open Type
This eclipse keyboard shortcut helps in finding java classes from project and from jars file as well.


Ctrl + T - open Type hierarchy
This eclipse keyboard shortcut helps in showing the hierarchy of the current Java class.
Example - Object class is superclass of all classes.


Once type hierarchy is opened as shown in above diagram. You may >
  • press Ctrl + T again to see supertype hierarchy


  • press Ctrl + T again to see subtype hierarchy



Ctrl + O : Open declarations
This eclipse keyboard shortcut helps in finding all the members of class like declared variables, constructor, methods in java.

  • Now, press Ctrl + O again to show inherited members


  • press Ctrl + O again to hide inherited members


Ctrl + E - Open Editor
This eclipse keyboard shortcut lists the files opened in editor.

F3 - Open Declaration
This eclipse keyboard shortcut enters definition of method or declaration of variable.

Alt + Left (Alt + ←) or Alt + Right (Alt + → ) - Back to ... OR Forward to ...
Equivalent eclipse toolbar link is

Ctrl + Shift + F - format the code.
This important Eclipse keyboard shortcut allows you format files like java class, interface, xml, jsp, text, config, property and log files etc.


Tip - For Example you want to format whole file, Ctrl + A and press Ctrl + Shift + F.


Ctrl + Space - Content assist or code completion
This important Eclipse keyboard shortcut gives suggestion to you to complete your code.
Example -



Eclipse keyboard shortcut to Comment and uncomment code >


Ctrl + / : Line Comment / Toggle comment
  • This important Eclipse keyboard shortcut allows you to comment/uncomment current line or
Let’s say code is -
Now, when you press Ctrl + / code becomes -
  • you may select multiple lines and comment/uncomment them using this shortcut.
Let’s say code is -
Now, when you press Ctrl + / code becomes -


Also, you must know (Ctrl + 7 and ctrl + shift + c) allows you to toggle comment.


Ctrl + shift + /  -  Add block Comment
Let’s say code is -
Now, when you press Ctrl + shift + / code becomes -


Ctrl + shift + \  -  Remove block Comment
Let’s say code is -


Now, either select code or place cursor in between code and when you press Ctrl + shift + \ code becomes -





Ctrl + s - saves current file.
Ctrl + shift + s - This eclipse keyboard shortcut saves all files opened in editor.


ctrl + z - Reverse\undo changes
ctrl + z - redo changes.

Ctrl + F -  find or replace in file.
This eclipse keyboard shortcut can be used to find or replace in file test in file.
It gives you option search in forward and backward direction,
Wrap search - after reaching end of file start searching from top of file,
and also allows you to do incremental search.

Ctrl + F4 : Close current Editors (Ctrl + w also close current editor).
Ctrl + Shift + F4 : Close all the Opened Editors (Ctrl + shift + w also close all the Opened editors).
Ctrl + L  - go to line
This eclipse keyboard shortcut allows you to go to specific line number of file.


Alt + Shift + R : Eclipse keyboard shortcut to Rename package, class, project, class or interface. Even F2 allows you to rename.


Few more important eclipse keyboard shortcut in java
Alt + Shift + X - Run As…
Alt + Shift + D - Debug As…

Few more less used eclipse keyboard shortcuts -


Ctrl + 1 - Quick Fix - Result of pressing ctrl + 1 may be different depending on location of your cursor position.
This eclipse keyboard shortcut helps in fixing the errors quickly,


Example 1 -
Let’s user commits some spelling mistake like writing
System.out.printl("hi"); in place of System.out.print("hi"); or System.out.println("hi");, and he then presses Ctrl + 1, then he will be given quickFix (suggestions) in eclipse.


After quick fix >

Example 2 -

After quick fix >


Alt + Shift + W  - show class in different views like Package explorer, Navigator etc.
This eclipse keyboard shortcut helps to view class in different view like Package explorer, History, Navigator, Project Explorer etc.
Example - Let’s say current I am viewing class in package explorer, press Alt + Shift + W and select Navigator.


After selecting Navigator, class will be displayed in Navigator >


Alt + Shift + S + R  - This eclipse keyboard shortcut helps in generating getter and setter methods for member variable of class.



Ctrl+Shift+L - It helps in viewing all the eclipse keyboard shortcuts.
Pressing Ctrl+Shift+L again opens preference page where you can see all the eclipse keyboard shortcuts and even may change or set new eclipse keyboard shortcut.

Ctrl + D -  Delete current line, if multiple lines are selected this eclipse keyboard shortcut can delete multiple lines as well.


Ctrl + Shift + DEL - This eclipse keyboard shortcut deletes till end of line


Ctrl + DEL - This eclipse keyboard shortcut deletes next element in file.


Ctrl + BACKSPACE - This eclipse keyboard shortcut deletes previous element in file.


Ctrl+Q - Find the last edit

Alt + Shift + L : Extract to Local Variable  (Refactor java code)


Let’s say code is -


Now, select x + y and press Alt + Shift + L, give variable name (in this case I have given it as i)  and press OK.


Code becomes like these -
x + y is extracted to local variable and i and all the occurrences of x + y in code are replaced with i. It makes code more readable, efficient and quick as calculations are not performed repeatedly.

Alt + Shift + M : Extract to Method (Refactor java code)
Let’s say code is -


Now, select x + y and press Alt + Shift + M and give method name (in this case I have given it as addMethod)   and press OK.


Code becomes like these -
x + y is extracted to local method.

Alt + Shift + I : Inline  (Refactor java code)


So, in this java eclipse tutorial we learned most important frequently used eclipse keyboard shortcuts.

eEdit
Must read for you :