When working with any tools, not only Eclipse, using shortcuts will help us save time compared to using mouse. In this tutorial, I will introduce some popular shortcuts in Eclipse!
Ctrl + D
When you want to delete one row, simply you only need to leave your mouse on the row and press Ctrl + D. Selecting all the text in a row and pressing the Delete button will take your time.
Alt + Up | Down
Combination between Alt + Up or Alt + Down can help you move your code up or down to arrange them.
Example, I have a piece of code as below:
I want to move this line
up to top, I only need to leave my mouse on this line, keep the key Alt, and double press the Up key.
Alt + Left | Right
Go to next place and previous place of code which we just edited.
Example, you just edited the code in class A and now you are working on class B. If you want to go to the place that you just edited in class A, you only need to press Alt + Left. After you went back to the place in class A, now you want to go back to class B, just press Alt + Right.
Ctrl + 1
This keys will active the function Quick fix of Eclipse.
One example about using the combination between Ctrl and 1 is: you initialize a new object by using the operator new.
Now, you want assign for this object reference to a variable. In this case, you only need to leave your mouse at this line, press Ctrl + 1, one popup will be displayed as below:
Select Assign statement to new local variable if you want to assign your object into a reference variable as a local variable, or Assign statement to new field if you want this variable as a global variable.
Ctrl + Shift + O
A combination of these keys helps us import all classes which are used in our class if they haven’t been imported yet.
When you press these keys, all using classes will be imported and all non-using classes will be removed.
Ctrl + Shift + T
Using to search and open a class in our workspace. Quick and convenient!
Ctrl + Shift + F
Format our code.
Formatting code is very necessary for our code, it will help our code be clear, easy to read, and maintain. You can edit the setting of formatting code by: Window –> Preferences –> Java –> Code Style –> Formatter.
Ctrl + Shift + G
Search where the class or the method is using in our workspace.
For example, I need to find out where class A or method A is used in my workspace, simply I only need to leave my mouse on the name of class or method, then press Ctrl + Shift + G, all reference to my class or my method will be displayed.