The Easiest Ways to Navigate Methods in a Class using Eclipse Keyboard Shortcuts

java classes can get big and hairy, making it difficult to find the method you’re looking for when browsing or editing a class. there is no specific order to where methods can be in a class and different developers have different preferences about where to put them.

you could use the mouse wheel and scroll ferociously until you eventually find the method or you could even use page down/page up on your keyboard. but these methods can be time-consuming and haphazard, especially when the class has lots of methods or they’re scattered in an arbitrary order.

luckily, eclipse has a number of fast and easy ways to help you navigate methods in a class, especially using the keyboard. i’ll discuss some of those keyboard shortcuts and also which ones to use when.

quick outline

the quick outline is basically a scaled-down popup version of the outline view. the main advantage over the outline view is that it has a search box that allows you to search for a method.

here’s how to use the quick outline:

this is an example of the popup for java’s arraylist .

searching for *rem will search for all method names that contain the word rem . here’s an example:

notes:

next member & previous member

another way to move between methods is to use two features called go to next member and go to previous member.

when you press ctrl+shift+down , eclipse moves the cursor to the next method in the class. pressing ctrl+shift+up moves to the previous method.

here’s a video to give you a quick example of how these shortcuts work:

this shortcut works best if you’re already positioned in a method or if the class has few fields. that’s because to eclipse a member can either be a method or a field. if you’re at the top of the class, you have to move through all the fields before you actually start moving through the methods themselves, a time-consuming process especially for bigger classes with lots of fields.

it helps to generate getters and setters at the bottom of the class because you don’t have to navigate through them to get to the useful methods.

open declaration

if you’ve got lots of private methods in your class then open declaration might be the best way to navigate between them.

when you’re positioned on a method call and press f3 , eclipse takes you directly to the definition of that method. for example, if you’re busy in the method process() and your cursor’s positioned on initprocessing() , pressing f3 will take you directly to the declaration for that method further down the class.

public void process() {
//do things...
initprocessing();
//...
}
...
private void initprocessing() {
//init something...
}

this feature works very well with alt+left (backward history). see the section below for more details about the backward history.

navigating back to a previously viewed method

while browsing code, you’ll often want to return to the previous method you were viewing once you’re done viewing the method it calls.

to do this, use alt+left (backward history) to move back to the last navigation point. this feature isn’t specific to just methods, but also works for navigating between previously visited editors. but it works great if you’ve just been browsing methods within a class.

quick mentions

what should i use when?

from http://eclipseone.wordpress.com/2011/02/21/the-easiest-ways-to-navigate-methods-in-a-class-using-eclipse-keyboard-shortcuts/

 

 

 

 

Top