The built-in auto-suggestion feature in Eclipse, known as Content Assist, is a powerful tool for accelerating coding. While it can be manually triggered with a keyboard shortcut, you can enable it to activate automatically as you type by adjusting a simple preference setting.
How to enable and customize auto-suggestions
Step 1: Open Eclipse preferences
First, open the main preferences dialog in Eclipse.
- On Windows and Linux: Go to Window > Preferences.
- On macOS: Go to Eclipse > Preferences.
Step 2: Navigate to Content Assist settings
In the Preferences window, use the search bar or the navigation tree to find the relevant settings.
- Expand the Java section.
- Expand the Editor section.
- Click on Content Assist.
Step 3: Configure auto-activation triggers
In the Content Assist pane, look for the "Auto Activation" section.
- Enable auto activation: Ensure the "Enable auto activation" checkbox is checked. You can also adjust the
Auto activation delayhere, which is the amount of time Eclipse waits before displaying suggestions. - Define triggers for Java: In the "Auto activation triggers for Java" text field, you can specify the characters that cause the suggestion box to appear.
- The common, most effective setting is to enter all lowercase and uppercase letters, the dot operator, and other special characters:
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._@. - The period (
.) is a critical trigger for suggesting methods and fields for an object. - The at-sign (
@) is helpful for triggering annotation completion.
- The common, most effective setting is to enter all lowercase and uppercase letters, the dot operator, and other special characters:
- Refine proposals (optional): Click the "Advanced" button to fine-tune the types of suggestions that appear. In the dialog, ensure that relevant proposal categories, such as
Java Proposals,Java Type Proposals, andJava Non-Type Proposals, are selected. This is also a helpful step if you find the default suggestions are not working as expected.
Step 4: Apply and close
After making your changes, click "Apply and Close" to save your new settings. The changes should take effect immediately.
Additional troubleshooting and tips
If auto-suggestion is still not working, consider these steps:
Use the keyboard shortcut
Even with auto-activation enabled, the manual trigger remains a fast way to get suggestions. The default shortcut is Ctrl + Space.
Disable automatic insertion
By default, Eclipse might automatically insert a suggestion if you type a character that triggers it, which can be annoying.
- Go to Window > Preferences > Java > Editor > Content Assist.
- Check the box for "Disable insertion triggers except 'Enter'".
Address common conflicts
In some operating systems, particularly on Linux (e.g., Ubuntu) and macOS, the Ctrl + Space shortcut is used for other system-wide functions.
- On Ubuntu: This shortcut is often assigned to change keyboard input methods. You must reassign it in your system's keyboard settings.
- On macOS: Check System Settings > Keyboard > Input Sources to unbind
Ctrl + Spacefrom the "Select next source in Input menu" feature.
Refresh your project
Sometimes, Eclipse's internal index becomes corrupted. To fix this, try the following:
- Right-click your project in the Package Explorer.
- Select "Close Project".
- Right-click the project again and select "Open Project".
Check for corrupted workspace
If refreshing the project doesn't work, there may be an issue with your workspace.
- Close Eclipse.
- Rename the
.metadatafolder inside your workspace directory. - Restart Eclipse, which will create a new, clean workspace.
- Re-import your projects using File > Import > General > Existing Projects into Workspace.
Install language-specific extensions
For languages other than Java (e.g., C/C++, JavaScript), ensure you have the correct Eclipse plug-ins installed. The configuration for Content Assist may also vary slightly depending on the language.
Enhancing your auto-suggestion experience
Beyond basic auto-activation, you can use these features to boost your productivity with Content Assist:
Template proposals
Eclipse can generate boilerplate code from templates, which are also suggested via Content Assist.
- Typing
sysoutand pressingCtrl + Spacewill generateSystem.out.println(). - Typing
mainand pressingCtrl + Spacewill generate thepublic static void main(String[] args)method signature.
Organized imports
Use the Ctrl + Shift + O shortcut to automatically add and organize any necessary import statements, which ensures Content Assist can correctly identify classes from imported packages.
Generating getters and setters
You can auto-generate accessor methods for your class fields.
- Right-click within your code.
- Select Source > Generate Getters and Setters....