Saturday, September 17, 2011

Best Of Short Cuts For Eclipse: Ctrl + Shift + L

These are my most important short cuts after 8 years of busy java coding.
Increase your productivity and impress your coworker.

I will show you the predefined short cuts, how to define your own and the way to reuse them in all your eclipse IDE's.



Predefined Bindings
You can find an official overview of the predifined short cuts by clicking under Help -> Key Assist or more apropriate with the following short cut Ctrl + Shift + L.

Changing the code:
Ctrl + D Delete Line
Ctrl + Alt + Up/Down Duplicate Lines
Alt + Up/Down Move Lines
Alt + Shift + R Rename - Refactoring
Ctrl + Z Undo
Ctrl + Y Redo
Ctrl + Shift + O Organise Imports
Ctrl + Shift + F Format
Ctrl + Space Content Assist
Ctrl + 7 Toggle Comment

Navigating the code:
F3 Open Declaration
Ctrl + mouse over Open Declaration, (Super) Implementation
Ctrl+T Quick Hierarchy (like above without a mouse)
F4 Type Hierarchy
Ctrl + Shift + T Open Type
Ctrl + K Find Next
Ctrl + Shift + K Find Previous
Alt + Left Backward History
Alt + Right Foreward History
Ctrl + Alt + H Open Call Hierachy

Organise Imports
Be aware, it removes static imports like the handy one for junit
import static org.junit.Assert.*;
There are two solutions:
1. You can fix this by going to Window -> Preferences -> Java -> Code Style -> Organize Imports
There you change in the field 'Number of static imports needed for .*' the number of 99 to 1.
This is the number of static import statements that are allowed for static members of the same type before type is used.
2. Another way is to use the favorites of the content assist function.
Go to Window -> Preferences -> Java -> Editor -> Content Assist -> Favorites.
Enter a 'New Type...' like 'org.junit.Assert.*'.
When you use the next time the auto complete Ctrl + Space the it will propose those static members even if the import is missing.

Format
You can find the configuration under Window -> Preferences -> Java -> Code Style -> Formatter



Custom Bindings
Go to Window -> Preferences -> General -> Keys
Alt + W P 'keys' down down

Here you can look up all available commands and their key binding. Look at the command 'Activate Editor' it has a binding for the key 'F12'. One line above, the command 'About' doesn't got one.

We will add one binding step by step. In the filter field 'type filter text' type in 'generate'. Now the list shows 5 items. Select the command 'Generate Getters and Setters'.
Go to the 'Binding' field. As you start to press a button it will come up there with a trailing +.
If you press a combination of keys they get conncatenated in the order you pressed them with the +.
For generating getters and setters I would naturaly choose Ctrl+Shift+G.
This will lead to a conflict with the command 'References in Workspace'. Resolve it by choosing another key combination : Ctrl+Shift+S

Suggested:
Ctrl+Shift+S Generate Getters an Setters
Ctrl+Shift+E Show In (Package Explorer)



Reuse

Go to File -> Export... -> General -> Preferences.
Choose "Export all" or just "Keys Preferences".
To import them works the same way.

No comments:

Post a Comment