Eclipse tips (for Java development)

Type more to avoid excessive mouse mileage

  • <ctrl-shift-t>: Opens a class by typing it’s name. Also accepts wildcards.
  • <ctrl-shift-r>: Opens other files than classes.
  • <ctrl-o>: Jumps around in a class by typing member variable or method names. Also accepts wildcards.

Doing more with less typing

Use <ctrl-space> auto-complete everywhere:

  • Create a for loop or a switch-case just by typing the name of the structure
  • Create a new getter and setter methods by typing getVariableName
  • Create a new metrhod overriding a super class
  • Create a try/catch/finally block
  • And plenty more. if there is something you type often, like a logging call, add it as a content assistant template yourself from the preferences.

Use <alt-shift-r> when refactoring to rename all instances of a class, method, or variable.

Use <ctrl-1> to quickly fix simple error markers.

Managing changes

My favorite feature in Eclipse, that I haven’t found on many other IDEs, is the quick diff against version control. You can configure an editor view to show lines that have changed compared to the version you have in your version control. The changes are shown as markers in the margin. Hovering with mouse shows the original code and with right click you can revert parts of the file to previous version.

First enable team support (git/svn/etc.) for you eclipse project, then:

  • Enable quick diff margin (Preferences-> type quick diff to the search). By default the quick diff only shows unsaved changes. Change it to use your version control system.
  • I also change the colors to lighter green for changes and darker green for additions
  • Enjoy

I don’t otherwise use the version control integration in eclipse. I only have it configured to use quick diff. Quick diff is actually the reason I do even my C++ development currently on eclipse (even if CDT is not that great compared to the Java side of things).