When I started developing with Eclipse I was slow, now I’m at least 3 times faster than before. The main reason is that i’m now using some time saving shortcut keys. In this post, I’ll present the most useful key bindings I use.
The ultimate navigation combo
I often need to understand legacy code before adding mine. The following shortcut keys are helping me a lot when it comes to reading someone else’s code:
- Ctrl + mouse over an element: Eclipse will proprose you to open the declaration, the implementation, the super implementation … of the element. The possible actions depend on the element.
- Alt + Left arrow: If you have opened a declaration/implementation of an element and you want to go back to the line of code you were before, this is the shortcut key you need
- Ctrl + Shift +T: Sometime I need to open a class or an interface that I partially remember the name. This shortcut key will open the “Type research” which works with camel case and *. By example, if you’re looking for the class ThisIsATestYeah and you enter whether TIA or *I*sTest: the search quickly displays the class ThisIsATestYeah and you just have to click on the class to open it.
- Ctrl + Shift + R: Same as Ctrl + Shift +T but this time you can look for patterns in all the file names of your open projects.
- F2: Force Eclipse to show the description (if there is one) of the selected element
I’m always modifying my code so here are my time saving shortcut keys, only the first one is essential:
- Alt + Shift + R: Rename/Refactor the selected element. Very handful since it modifies the name of the selected element in all the parts of the code using the element.
- Ctrl + Shift + F: Format code. Very useful to indent the code. You can modifty the formatter in “Window > Preferences > Java > Code Formatter”. You can also run this action automatically on save in “Window > Preferences > Java > Save Actions”
- Ctrl + Shift + O: Organize imports. Not very useful but I use it to remove unused import after some deletions. You can also run this action automatically on save in “Window > Preferences > Java > Save Actions”
- Ctrl + K : Find the next occurrence of the currently selected text. Way better than the “classical” Ctrl + F since it requires only one action
- Ctrl + Shift + K: Find the previous occurrence of the currently selected text
- Ctrl + H: will open the search dialogue. I use it when I need to look for a pattern in all my projects files (java, xml, properties)
- Ctrl + L: then enter the line number you want to go. Useful when I need to understand the cause of an exception
When I finish writing some code, I always need to run/debug the java code or the associated unit test or launch a maven build. The following shortcut keys are not very important but knowing them can save you some time:
- Alt + Shift + X then J: Run the java application (if there is a main() function in the current code)
- Alt + Shift + D then J: Debug the java application (if there is a main() function in the current code)
- Alt + Shift + X then T: Run the unit test (if the current code is a unit test)
- Alt + Shift + D then T: Debut the unit test (if the current code is a unit test)
- Alt + Shift + X then M: Run the maven build