provides software and services that enable enterprises
Live Chat 1-888-673-6564

Open Source Software Technical Articles

  • Home
  • Search
  • Contact Us
  • Products and Support
  • Services
  • Enterprise OSS Blog
  • Wazi Technical Blog
  • About Wazi
  • Attributions and Licensing
  • Supply Chain Compliance
  • How to Contribute
  • Contributors
  • Resources Library
  • Cloud Services
  • Partners
  • Customers
  • Community
  • Company
  • Careers
  • News and Events

Subscribe to Wazi by Email

Your email:


Enterprise Developer Support 24 x 7, Get a Support Quote Now!


click-here-to-chat-with-an-online-representative

download-oss-discovery

Latest Posts

  • Use Perl to enhance ModSecurity
  • The secret to great reporting with Drupal 7
  • A more colorful LibreOffice unveiled
  • Toward a more colorful LibreOffice
  • Flexible administration with Puppet's Facter and templates
  • Knock for OpenSSH
  • Get more out of phpMyAdmin
  • Image annotation in GIMP, Dia, and OpenOffice Draw
  • Solr, Drupal 7, and faceted search
  • Using FreeNAS' new full disk encryption for ZFS

Connect with Us!

Current Articles | RSS Feed RSS Feed

Eclipse productivity tips

Posted by Juliet Kemp on Mon, Sep 17, 2012
  
Email This Email Article  
Tweet  
  

If you code in Java, chances are you've used the Eclipse integrated development environment. If you're not a Java coder, you may have used Eclipse for one of the several other languages it can support via plugins. Even so, you may not know all the tools that are available for the Eclipse power user that can rocket your productivity levels upward. Check out these tips on helpful keyboard shortcuts, setting up the editor, and navigating at speed through your code.

One note: These keyboard shortcuts work as stated for Linux and Windows environments. If you're on a Mac, substitute Cmd for Ctrl unless otherwise noted.

Navigating your code

Even small Java projects can get unwieldy quickly, and using the mouse to invoke a search through the source tree for classes, variables, or types can take too much time. Keyboard shortcuts can get you back to coding as fast as possible.

The most important shortcut is Ctrl-T, which generates a pop-up window with the type hierarchy of the object under the cursor. If the cursor is on a specific variable, you get information about that variable; if it's on a class name, you get information about the class. Press Ctrl-T again to see super-types as well. Highlight the line you want in the window and press Enter to navigate there in the code.

If you try to open a Java (JDK) type from here, you'll get an error. Instead, to open a Java (JDK) type, use Ctrl-Shift-T; this opens types that are in the JDK, not just in your workspace. However, note that this keystroke searches on the highlighted text, not the object under the cursor.

More generally, you can search for a particular resource of any sort within your workspace by using Ctrl-R.

If you just need to navigate through your current class, instead of using the little Outline window you can hit Ctrl-O to display class members, then Ctrl-O again to show inherited members. Start typing a method or variable name to search as you type, and press Enter to go straight to that class member. Once you get used to this, you can close down the Outline window and free up a bit of screen real estate. I don't know about you, but the more of my screen I can spread my code across, the happier I am.

Finally, to search for other references in your workspace to a particular item, move the cursor to it and press Ctrl-Shift-G. The references will all show up in the search box, which is usually to be found at the bottom of your workspace.

Moving around within the editor

As well as moving around within the codebase, you want to move around within the editor. Keyboard shortcuts can help you here too.

To access the list of open editor windows, press Ctrl-E. The list that pops up shows the most recently opened windows; click to expand and show them all. You can just start typing to do an incremental search of the list, which is great if you have a complex project with a lot of edit windows open.

To return to the last edit location, press Ctrl-Q (on a Mac, it's still Ctrl-Q, not Cmd-Q). You can also navigate backward through your edit history by pressing Alt+left arrow (Cmd-] on a Mac).

Keyboard shortcuts for fixing and tidying code

One helpful feature of an IDE like Eclipse is that it can highlight code problems before you get as far as compiling and testing. If you see the telltale red underline that indicates a problem in your code, you can press Ctrl-1 to pop up the quick fix menu, which suggests some common options to resolve the perceived problem. This is particularly great for adding imports. You can perform a whole bunch of quick fixes here, including creating new class variables, changing potential typos, and creating methods.

As well as fixing problems, Eclipse can help you to make your code more readable. While you're writing or editing code, chances are that at some point you'll screw up the indentation. Eclipse can fix this up for you – just select the text and press Ctrl-I. If your local coding standards don't match the Eclipse default, you can edit them by creating a new profile under Eclipse Preferences -> Java -> Code Style -> Formatter.

Another common code-tidying situation is refactoring. Though it's a bit tedious when done by hand, with the help of Eclipse it's a snap. Use Shift-Alt-R to rename a variable. (I love this shortcut; it has saved me hours with find and replace.) No more excuses for misleading variable names! Shift-Alt-L extracts code to a local variable, and Shift-Alt-M extracts it to a method. (On a Mac, use Alt-Cmd-letter for all of these.)

To comment out a block of text quickly, select it and press Ctrl-/. Hit it again to uncomment; this is a great help when you're tracking down bugs or experimenting with different ways of doing things.

Using editors

Coders are often picky about the details of how their editor works – unsurprising, given how much time we spend typing. Eclipse allows you to set a lot of preferences under Eclipse Preferences -> General -> Editors -> Text Editors. You can set tab size and spaces, how the hover behaves, and various appearance color options. You can also configure the spellcheck and a selection of keybindings under Editors -> Keys, and set more preferences under Java -> Editor.

Alternatively, you can set the whole keybinding scheme to match your preferred text editor. To use Emacs-style key bindings, use Eclipse Preferences -> General -> Keys and set the scheme with the top drop-down. If you're a Vi(m) user Eclipse doesn't give you built-in support, but a couple of plugins do the trick. I use Viable, which is free to try, then $15 CAD to remove popups. In my opinion it's worth the money. Vrapper is free and many coders seem to get on well with it. viPlugin is another option.

If you're partial to a particular external editor and can't quite get Eclipse to work the way you want it to, you can set a particular file type to be opened by an external editor. Go to Eclipse Preferences -> General -> Editors -> File Associations, highlight the relevant file type, then click the Add button under Associated editors and choose your external editor. Files of your chosen type will now be opened automatically in this editor. Bear in mind that by doing this you lose a lot of the benefits of Eclipse. For certain file types the tradeoff may be worth it, but in general it's probably a better idea to fiddle with the preferences or look for a plugin to help out.

If you want to use an external editor only very occasionally, you can set up the External Tools option to send the current buffer to an external editor instance. Go to Run -> External Tools -> External Tools Configuration and create a new Program configuration. Call it something sensible, such as "Open in Vim," and enter in the Location box the path to your editor (e.g. /usr/bin/gvim). Working Directory should be ${project_loc} (use the Variables button to check out other variables), and Arguments should be ${resource_loc}. These identify the current project directory and the current resource (file). Once you're set up and you're in an editor window, use the Run -> External Tools menu to send the file to an editor. This is a useful technique for occasional use.

You can check out the Eclipse help pages for more on editors.

Another massive Eclipse time-saver is templates; you can read more about them in this article.

Follow @openlogic
Follow @OSCloudServices

This work is licensed under a Creative Commons Attribution 3.0 Unported License
Creative Commons License.
Tags: Eclipse, Tips & Tricks, Java

Comments

Honestly, the best way to get more productive is to purchase the license for IntelliJ. Eclipse is so slow and clunky that one can never aspire to any actual productivity. And if you're using Maven, there's nothing worse you can do to yourself than use Eclipse. It's Maven integration works horribly, and that is when it works at all. If for any reason you can not use IntelliJ, go for NetBeans at least. It's been worse than Eclipse some years ago, but is now much, much better.
Posted @ Wednesday, September 19, 2012 8:14 AM by veggen
I disagree with the previous comment. The speed of Eclipse is highly dependent on your machine. If you have shitty hardware, software will seem shitty. It's true that monolithic IDEs use a ton of ram and suck as much power as they can get.. but that's the nature of the beast. -Any- IDE will have this type of problem. 
 
Fortunately, every release gives speed improvements on existing hardware and there is a point at which most sufficiently complex IDEs won't suffer once you have a base line hardware config. 
 
Also, it all depends on what you are trying to do with it. ie. If you have 20 projects open at once YES, expect it to be slower than if you have just 1. Also how many plugins and the feature set you are working with affect the performance.
Posted @ Tuesday, April 30, 2013 10:41 AM by Bob
Post Comment
Name
 *
Email
 *
Website (optional)
Comment
 *

Allowed tags: <a> link, <b> bold, <i> italics

Loading...
Error sending email
Email sent successfully

Email article
Email To : 
Your name : 
Message : (maximum 200 characters)
Home | Search | Contact Us | Products and Support | Services | Enterprise OSS Blog | Wazi Technical Blog | Resources Library | Cloud Services | Partners | Customers | Community | Company | Careers | News and Events
Products
OpenLogic Exchange (OLEX)
License Compliance Module
OSS Discovery
OSS Deep Discovery
OpenUpdate
Services
Open Source Support
CentOS Support
Scanning & Compliance
Open Source Training
Professional Services
Solutions
Support & Indemnification
Open Source Governance
Open Source Scanning
Open Source Provisioning
Consulting & Training
Contact Us
1-888-673-6564


© 2013 OpenLogic, Inc. All rights reserved.
Site Map  |  Privacy Policy