8+ simple tips to boost your productivity with Eclipse
Bookmarking for Developers & Co with www.bookmarks.dev. Use our Add to Bookmarks.dev bookmarklet to your bookmarks toolbar for a seamless experience. Share your favorites with the community and they will be published on Github - Star
1. References of used class/method in code
This is a very quick and useful way to find out where a class or method is used throughout the workspace/project. How to do it – select class/method > right click > References > Workspace (Ctrl+Shift+G) || Project
Once you’ve done that, the results will be displayed in the Search view:
Another alternative for that is by selecting the class/method > start Java Search (Ctrl+H) > select your search criteria (in this case Type) and limit to References:
So I’ve found out where the method is used or where I want to modify some code. For sure I might want to go back to that location several times before I am finished. I don’t want to search for the location in code every time so I just bookmark it! How to do it – go to the left margin of the code view (where you set the breakpoints) > right click > Add bookmark…
3. Use the “search in file” function
By now we all know how important search is, otherwise you wouldn’t have probably found my post in the first place… The same holds true for code – we don’t have to remember everything. As long as we remember something to put in the search box we can look for it
Menu > Search > File…
For example I know I have a
select identifier in the MyBatis mapper (
.xml file) called
getPodcastById. The faster way to navigate to it is to search it in
.xml files, instead of clicking myself through the Package Explorer view:
4. Open declaration/implementation
Long gone are the times when we didn’t have to look in the source code of the frameworks/products we were using :). Provided that you downloaded the java sources/docs (e.g. in Maven projects : Eclipse Menu > Window > Preferences > Maven > Download Artifact Sources/JavaDoc), you can quickly go to the implementation/declaration, by holding the Ctrl key and then hovering with the mouse over the class/method:
Of course you can use the same functionality to quickly navigate to the declarations/implementations in your own projects.
Note: A quicker way to open the declaration of the class/method is by selecting the method/class and pressing F3.
5. Use multiple workspaces
Don’t clutter your workspace with many projects, that might not have any correlation with each other. It’s more efficient to group related projects (could be just one project) in their own workspace and create different Eclipse shortcuts for each workspace.
-dataparameter (e.g. “C:\eclipse\eclipse.exe -data C:\workspace\git“)
- Name your workspaces Window > Preferences > General > Workspace:
It will help you navigate easier between open Eclipse instances in the taskbar.</li>
- Reuse configuration when creating a new workspace – you can keep the configuration of one work space (Java, Maven settings etc.) when you create another one, by just copying
.metadatafolder created by Eclipse of your current work space in the new work space’s folder.
- Store the projects outside of the workspace if you want to share them across different Eclipse versions.</ol>
6. Use shortcuts
For faster development you should use more of the keyboard and less of the mouse. Apart from the classic shortcuts Ctrl+c (copy text/file to clipboard), Ctrl+v (paste text/file from clipboard), Ctrl+z (undo last action), Ctrl+y (redo last action), and Ctrl+s (save), Eclipse supports keyboard shortcuts for the most common actions. There are dozens of them, but if you know the “important” ones, you should be fine.
I’ve listed below the ones I use most frequently :
|Alt+Shift+R||Rename selected element and all references in project|
|Ctrl+Space||Content assist/code completion|
|Ctrl+1||Quick Fix – Suggest possible fixes for a problem, or shows possible actions (let Eclipse create local variables, constants, choose their name and realize the necessary imports / initialize local variables / assign the result of a method to a new local variable)|
|Ctrl+Shift+T||Open Type – Open a type in a Java editor|
|Ctrl+Q||Goes to the Last edit location|
|Ctrl+7||Toggle comment the selected linets|
|Ctrl+O||Shows quick outline of a class|
|Ctrl+Shift+O||Organize imports – Evaluate all required imports and replace the current imports|
|Ctrl+F||Opens the find dialog|
|Ctrl+k/Ctrl+Shift+k||Find previous / next occurence of search item (close find window first)|
|F3||Open declaration – Jump to declaration of selected class, method or parameter|
|Ctrl+M||Maximize active editor or view|
|Ctrl+Shift+F||Format source code|
|Ctrl+E||Show a list of open editors|
|Ctrl+F6||Move between open editors – a slower alternative to Ctrl+E|
|Alt+<||Go to the previous opened editor. Cursor is placed where it was before you opened the next editor|
|Alt+>||Similar Alt+< but opens the next editor|
|Ctrl+PageUp||Switch to previous opened editor|
|Ctrl+PageDown||Switch to next opened editor|
7. Use code templates
Templates are a structured description of coding patterns that reoccur in source code. The Java editor supports the use of templates to fill in commonly used source patterns. Templates are inserted using content assist (Ctrl+Space).
Typing the code for a loop to run through a collection of Podcasts so that I can perform some sort of action with every Podcast can be a “tedious” task. But using templates in Eclipse this can be very easy. I just type
for in the editor and prest Ctrl+Space:
Templates are not only Java-specific and are defined in the Preferences pane under the specific plug-in with which they’re associated — for example, Eclipse > Preferences > Plug-inName > EditorName > Templates. If you do a search on Templates in Preferences you might get something like the following:
You can also define your own code templates, but this is a story for a dedicated post. There are plenty of resources on the web for that, some of which I listed under Resources.
8. Save actions
With Window > Preferences > Java > Editor > Save actions
you can automate some of the boring tasks like format source code, organize imports and even add additional actions, when saving your work.
Well, these are the initail eight simple tips. I hope I could help you speed up your development in Eclipse. If you have been using them already, even better and if you see I am missing something major here, please leave a comment and I will add it to the post – thanks!
If you’ve found some usefulness in this post this, I’d be very grateful if you’d help it spread by sharing it on Twitter, Google+ or Facebook. Thank you! Don’t forget also to check out Podcastpedia.org – you’ll find for sure interesting podcasts and episodes. We are grateful for your support.
- Effective Eclipse: Shortcut keys
- Visual Guide to Templates in Eclipse
- Java Save Actions Preferences