Over a million developers have joined DZone.

Eclipse Features With Hotkey Combinations

DZone's Guide to

Eclipse Features With Hotkey Combinations

· Java Zone ·
Free Resource

Java-based (JDBC) data connectivity to SaaS, NoSQL, and Big Data. Download Now.

Using Eclipse with hotkey combinations can be like playing a video game. Mortal Combat particularly comes to mind. To be good at Mortal Combat, you must memorize a slew of game-pad sequences. For example, to perform the Sub-Zero Skeleton Rip on your enemy, you must do a Back, Forward, Forward, Down, X-button on the game control pad. Well, Eclipse is no different. The joystick in this case is any combination of Control, Alt, Shift, letters, numbers, and F-keys. Let's go through my favorites in order of most frequently used. ( Note: these are tested in Eclipse version 3.02 and up.)
  1. Control-Shift-T: Open type. Forget manually navigating through the source tree unless you're procrastinating.
  2. Control-Shift-R: Open resource (looks for more than just Java files).

educational portal of india download free pdfA tip to go along with these first two combinations is in the Navigator view, accessed from the yellow double-arrowed Link With Editor icon. This will make the file you open appear in the navigator hierarchy, which is often good orientation information. Turn it off if things get too slow.

download music from mp3pa.com a  mp3 search engine

  1. F3: Open declaration. Alternatively, you can click on the Declaration tab (in the Java perspective, go to Window, then Show View, then Declaration). This key shows entire method declarations in the declaration pane when you click on a method call in the code.
  2. Alt-left arrow: Go back in navigation history. Works like a Web browser's back button and comes in handy after jumping around using F3.
  3. Alt-right arrow: Go forward.
  4. Control-Q: Go to last edit location. This key combination is also handy after you've been jumping around the code, especially if you've drilled down too deeply and have forgotten what you were doing.
  5. Control-Shift-G: Find references in workspace. Prerequisite to most refactors. For methods, this key combination is basically the opposite of F3, allowing you to navigate backwards up a method stack to find a method's callers. A feature related to this is turning on occurrence marking. Go to Window, then Preferences, then Java, then Editor, then Mark Occurrences and select a few checkbox options. This highlights all occurrences in the code when you click an element designated for marking. I personally only use Mark Local Variables. Beware: Enabling too many highlights can slow Eclipse.
  6. Control-Shift-F: Reformat code (according to code style settings). Our team agreed on a coding style, and we posted the Eclipse code style-rules files to our wiki. To do that, we sat together in Eclipse and went to Window, then Preferences, then Java, then Code Style, and configured Code Formatter, Code Templates, and Organize Imports. We used the Export function in each of these screens to generate the config files. We put these on the wiki and everyone imported them into their Eclipse.
  7. Control-O: Quick outline. Within the editor, this key combination allows you to jump to a method or attribute by typing a few letters of the name.
  8. Control-/: Comment/uncomment a line. Can also work on many lines at a time.
  9. Control-Alt-down arrow: Copy highlighted line(s).
  10. Alt-down arrow: Move line(s) down. Alt-up arrow works as well

Other hotkeys are listed on the menus. You can view a list of all keys by pressing Control-Shift-L (since version 3.1). Press Control-Shift-L a second time and it will take you into the Keys Preferences dialog where you can customize the key bindings. I welcome your Eclipse tips in the comments section.

Extra Eclipse nuggets

I'll conclude with a few related tips that come to mind:

Lock the Console window: In the Console view (Window, then Show View, then Other, then Basic, then Console), try the scroll lock icon to keep console output from slipping out of view.

Use the Ant view: In my Java or Debug perspective, I like to have the Ant view also showing so I can quickly run Ant tasks. Find this at Window, then Show View, then Other, then Ant. Then just place the view in a corner of the screen. Add build.xml files to it using the Add Buildfiles icon. Version 3.1 even has support for debugging Ant scripts!

Auto-iterate over a collection: for + Control-Space: If you didn't know already, Control-Space is auto completion. In Eclipse, you can auto-complete constructs too. In the scope of an array or a collection, try typing for (without a trailing space) and then pressing Control-Space. Eclipse will ask you which collection you'd like to iterate over and write the loop code for you!

Use the Hierarchical layout: The default layout (Flat) in the Package Explorer view distracts me with its full package names in a navigation tree. I like the package/file system view of my sources much better, which is called the Hierarchical layout in Eclipse. Switch to this in the Package Explorer view by clicking on the black down-arrow icon, then select Layout, then Hierarchical.

View multiple files at once: You can see more than one file at the same time by dragging a nonactive tabified editor to the bottom or side scroll bar of the open/active editor. That's the best way I can describe this nugget.

Open two instances of Eclipse simultaneously: To merge my changes from one CVS branch to another, I like to open two instances of Eclipse in different workspaces at the same time. Then I can see all the changes I've made by comparing them with the latest version in CVS (right click on the project, then select Compare With, then Latest from HEAD) and apply each change to another CVS branch. The easiest way to launch multiple instances of Eclipse is to use the Eclipse Launcher.

The Implementors plug-in: Add the possibility of jumping to the implementation of an interface. If you're a dependency injection fan or are just working with well-written interface-based code, you'll need this plug-in to speed code navigation. You'll find it at SourceForge.

Author: Chander Prakash is an Associate Software Engineer contributing to Rational Application Developer. He holds a Bachelor of Technology degree from Indian Institute of Technology, Guwahati. He has been a presenter at Rational Software Development Conference.He is also founder of educational portal of india called Globalshiksha.com

Connect any Java based application to your SaaS data.  Over 100+ Java-based data source connectors.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}