14 Eclipse Shortcuts and Productivity Tips – 2017 [Updated]

Eclipse is a popular IDE, no doubt! But I think everyone will agree that Eclipse far too many options and menus than a regular user can understand. Quite often Eclipse can feel like a big piece of bloatware, rather than an IDE designed for coding. So, in the interest of my readers, today I have got some important Eclipse Shortcuts and other productivity tips. Think of them as productivity hacks for Eclipse, which will help you code faster and save a lot of time.

Note: Anyone using Eclipse for more than 5 years, you may already know most of the tricks in this article.

Eclipse Shortcuts for Navigation

1. Open a class outline – CTRL + O

A class outline is a tree-like structure which shows all the members and functions of the class. You can click the method and quickly navigate to the location, you don’t have to scroll all the way.

Use CTRL + O to quickly open a class outline. It will show a detailed outline of your class, like this:

Outline of User Class with getter / setter and other methods

Outline of User Class with getter / setter and other methods

 You can see all the methods and data members. Just click on the one you want to navigate to. Easy-peesy, saves several seconds in incessant scrolling!

Bonus Trick for Eclipse IDEBonus Trick: This shortcut works on ALL files, and not just Java classes. But with tag-based files like JSP and XML, this will show an outline of tags i.e main nodes of your structure tree. This tree will not cover identification information which will help you locate tag for a specific purpose.

2. Organize all imports – CTRL + Shift + O

As you copy paste code from other classes, you can see the classes being automatically imported in the import block right above your class. Unfortunately, this feature doesn’t work the reverse way.

List of Unorganized Imports

List of Unorganized Imports

Meaning that when you remove code and some classes are no more needed, Eclipse doesn’t remove them from the import block automatically. This leaves you with the problem of “unorganized imports”. It leaves behind many unused imports with an ugly yellow underline, which means that the class being imported is not used in the file.

So, to quickly eliminate unused imports and organize the import block (remove empty lines, order them etc), simply press CTRL + Shift + O and your imports will be quickly cleaned up.

Organized imports after CTRL + Shift + O

Organized imports after CTRL + Shift + O

3. Show open Editors – CTRL + E

Just press CTRL and E keys at the same time, you will see a small popup showing list of open files in the top right corner.

This pop-up will let you navigate between the open files quickly without touching your mouse or taking your hands off your keyboard. You can use arrow keys to move up / down this list and press Enter key to switch to the editor of the file you want.

4. The “Search Resources” function – CTRL + SHIFT + R 

When you have a large number of files in your project, this shortcut will let you quickly open a file across ALL your open projects without having to open the project explorer.

Simply pressing CTRL, Shift, and R keys simultaneously opens the “Open Resource” dialog box. As you type in your file name, the suggestions will dynamically popup. Along with each suggestion you will also see the project path to which the file belong. A sample is shown in the below image:

"Open Resources" Window

“Open Resources” Window

This dialog box searches across your work space in all open projects and tags the search results with the project path as well. As you can also see the full path of each file, you will never get confused here even if you have files of same name in different projects.  Clicking or pressing ENTER key for a selected file in the above dialog box will open that file immediately. This functionality is a really cool one – it’s like having an x-ray vision into all your files.

Bonus Trick for Eclipse IDEBonus Trick: Use CTRL + Shift + T to search among all Java type names i.e classes. This is a subset of the above function as it restricts the search only to Java type names.

5. Using Bookmarks in Eclipse  

Bookmarks are a handy feature in Chrome, you don’t have to remember ugly URLs, and can delegate the job of remembering to the browser.

Bookmarks in Eclipse are lines of code which you access frequently. You can give the line of code a name and save it as a bookmark.

To add a bookmark, right-click in the marker bar for the line you wish to bookmark and click Add Bookmark.

(EDIT: The marker bar is the small vertical column on the left hand side of your file editor used to show special symbols such as when a user has overridden a method or defined a break point on that line)

To view all bookmarks or open a bookmarked location, you need to open the “Bookmarks” view in your Eclipse Workbench. Simply click “Window” menu > Show View > Bookmarks to open the Bookmarks view. A sample is shown below:

Bookmarks View in Eclipse

Bookmarks View in Eclipse

Simply double click any of the bookmarks to open that location. Bookmarks are an important feature, but as you can see they are not as cleanly implemented as they are implemented in a browser. Slightly more cumbersome, but still a useful feature especially when you have to constantly test one small function for different inputs.

Using Code Templates Eclipse

Have you used auto-complete feature on your smartphone keyboard? Eclipse has a similar feature for the code called as Code Templates. To use the code templates,

  • Type a small part of a pre-defined code fragment
  • Press CTRL + Enter keys simultaneously (Eclipse will complete the entire code fragment for you).

Code Assist, Auto Insert, Code Templates – they all mean the same thing. Eclipse gives you several of these pre-built templates in the Code Templates window. To check out how to define your own code templates, you can read our previous article on code templates which also has an example on how to do it.

Eclipse Shortcuts for Code Formatting

Code is not printed. So it is easy to ignore its formatting. However, looking at a code file after even 2 months, should be easy to read. Think about what it would be if your favorite website ignored all the indentation and published everything center aligned. How tacky would it look, right?

Fortunately, you don’t need to do much to clean up your code. Here are some really simple  shortcuts for eclipse for some really important code formatting tasks.

1. Format the Source Code – CTRL + Shift + F

Quickly fixes all indentation problems and makes it a lot more readble

2. Automatically insert Semi-colons – Eclipse Preferences Window

Eclipse also automatically pushes a semi-colon from middle of the code line to the end of the code line. To enable this setting, follow these steps:

“Window”  menu > Preferences > Java > Editor > Typing

From here just check “Semicolons” under “Automatically insert at correct position”. This is useful when you are typing code lines with long string literals or many methods chained together.

3. Automatically insert System.out.println ( ) 

There are two ways to do it:

a) Just type “sysout” and press Ctrl + Enter, it autoamtically gets converted to System.out.println(). You can now type your string to be printed inside the brackets.

OR

b) Type a string literal (along with double quotes), select the string to highlight it and press Ctrl + Space. After that press (End + Enter) key simultaneously,  the “sysout” snippet is triggered which wraps the selection around as its parameter.

4. Creating variables quickly without typing – Ctrl + 2, L

Helps you assign new objects to variables without actually creating the variables yourself. Just press CTRL + 2 and lift your fingers to press L.

5. Type Class and Method Names Faster – CTRL + Enter

Simply type the first letter of every word in the method or class name (with proper case) and press Ctrl + Enter to quickly complete it.

For example, to use toString() method, type “objName.tS” and press Ctrl + Enter.

Miscellaneous Fast Coding Tips in Eclipse

Maximize Current Editor – CTRL + M

Display All Eclipse Shortcuts – CTRL + Shift + L

Save Actions in Eclipse

Eclipse provides a bulk of options with heavy customization for different actions that you may need to perform when saving a file. This is done through the “Save Actions” window. Just follow the below path to open the window:

“Window”  menu > Preferences > Java > Editor > Save Actions

Check “Perform selected actions on Save”.

Check “Format source code”, “Organize imports”, and “Additional Actions” check boxes. For adding more actions, just click the “Configure” button and add more actions from the “Additional Save Actions” dialog box.

In this post, I have mixed both Eclipse shortcuts and options you can configure in Eclipse Preferences window. But that shouldn’t be your concern, should it? This is Eclipse tips and tricks article, not exactly a bench marking test.

If you are a student or a fresher, I would suggest you to put these Eclipse shortcuts as a skill in your resume. It may not add much weight, but at this level you need to differentiate from others as much as possible.

Use whatever works for you from this article, and if you find it useful, do let us know in comments 🙂

Leave a Reply