Monday, February 27, 2012

Really useful Eclipse shortcuts

I tended to remain skeptical about the advantages of using shortcuts in order to "gain more time". After all, how much time would you really save learning to use them? Well, I gave them a try. Even tough I think I didn't gain more time, I found myself using shortcuts instead of making abuse of "copy & paste" and learning from Eclipse suggestions while developing. So, I am putting here the shortcuts that I mostly use:

CTRL + 1
With this one, the scenarios where it is really useful are:
  • You have a variable in a class, with this shortcut you can refactor rename it.
  • You can switch between a local variable declaration and attribute of the class.
  • Or if you are creating the local variable and assigning a value to it in the same line, you can split it in two lines.
  • You have a call to a function that returns a value, with this you can automatically create a local variable or class attribute and assign the return value to it.
There are other suggestions possible that Eclipse will offer you, like rewriting code in other ways. You can learn a lot from those suggestions too! I really recommend the use of this shortcut.

CTRL + .
With this you can navigate through warnings or errors inside your class.

CTRL + F and CTRL + K
You open the find box with the first one, and look for other occurrences in the same file.

CTRL + SHIFT + O
To organize imports in your class, these are automatically deleted, added or a suggestion box may appear in case there are two classes with same name under different package in the project. This one is a must.

CTRL + SHIFT + R
To open a resource without losing time searching for it in the Package Explorer. This one is a must.

CTRL + O
It will ease the navigation though attributes and methods inside a class.

CTRL + 3
You can choose different commands Eclipse allows you to use, but instead of doing that through a graphical menu choosing your option, you can write the word and the command will show. E. G.: you want to create a new project then: press the shortcut, write "new project" and choose it, in the same way write "servers" to open the "servers" view.

CTRL + SHIFT + LEFT or RIGHT
This is like SHIFT + LEFT or RIGHT to highlight words, but the difference is that with this one you highlight complete words, not one at a time. This one in particular is not from Eclipse, but very helpful in everyday development :)

No comments:

Post a Comment