Using Eclipse shortcuts allows users to program most efficiently. Below are 8 useful shortcuts for newcomers to Eclipse.
- Install Eclipse Classic
- Install Eclipse SDK
- Install Eclipse IDE
1. Managing Imports: Ctrl + Shift + O
Whether working with Java libraries or third-party frameworks to add to your code, the truth is, to use these classes, you need to import them before Eclipse recognizes them as valid and available for code auto-completion (real-time import suggestions).
However, no one can remember all the package paths for every class in every library. Instead, use the shortcut Ctrl + Shift + O to automatically import unrecognized classes into your code.
2. Auto-indenting Selected Text: Ctrl + I
Simple and readable code is crucial, not only for you (in case you need to edit and understand what you've written) but also for other users when viewing code. Indenting text according to code format is essential.
Additionally, you can change how Eclipse handles indentation by accessing Window =>Preferences, then in the left-hand control panel, navigate to Java => Code Style => Formatter => Edit… => Indentation.
3. Delete Current Line: Ctrl + D
When coding in Java, you often need to delete multiple lines of code at once. The usual way to do this is to use the mouse to select the lines, then press Backspace. Another way is to press and hold End + Shift + Home simultaneously and then press Backspace. The quickest way, however, is simply to press Ctrl + D.
4. Auto Completion Suggestions: Ctrl + Space
Type in the first few characters of the class, method, or variable you want, then press the Ctrl + Space shortcut. This will bring up a list of auto completion suggestions along with the parameters for the method, variable types, and more. Select one character then press Enter.
5. System.out.println: type sysout and Ctrl + Space
When working with console applications, you need to use System.out.println() to print messages. However, this can be cumbersome, so Eclipse provides a shortcut: type sysout then press Ctrl + Space.
6. Project-wide Search: Ctrl + H
Working on large codebases, it's easy to forget the locations of specific classes, method attributes, or variables. Instead of wasting time searching repeatedly, you can use the shortcut Ctrl + H to perform a project-wide search.
By default, there are 4 types of searches: file search, task search, Git search, and Java search. While most people only use Java search and file source search, the other 3 types of searches are also useful in different scenarios.
7. Run Application: Ctrl + F11
To run a new project for the first time, navigate to Run => Run As… => Java Application. Then, you can speed up by using the Ctrl + F11 shortcut, running the current project using a configuration similar to the last time the project was run.
8. Rename: Alt + Shift + R
Useful shortcuts for newcomers to Eclipse for classes, method attributes, and variable names. You can imagine that renaming classes, attributes, or variables can take a lot of time.
Alternatively, another way is to right-click on the name, select Refactor => Rename, enter a new name, and Eclipse changes every reference in the entire project within 1 second. Or a quicker way is to click on any name, then press the shortcut Alt + Shift + R, enter a new name, and press Enter.