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:
- press ctrl+o from anywhere within the class.
- type a search term in the search box and eclipse will just show all methods that match the search term. by default eclipse does an exact match search, but you can use wildcards.
- once you see the method you’re interested in, press down to select the method (if it’s not selected already).
- press enter once the method is selected. eclipse will take you directly to the method’s declaration.
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:
- sort the view using the the down arrow menu in the top right corner. it makes it easier to find methods by scanning.
- resize the quick outline popup to see more methods. eclipse remembers the size of the popup for the next time you open it.
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.
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
- eclipse’s outline view also allows easy navigation but mostly with the mouse. you could navigate to the view using alt+shift+q, o , and you can move to methods by typing their first letter, but i’ve found the quick outline to be more keyboard friendly. also, the outline view doesn’t support wildcard searches.
- you can also use eclipse’s call hierarchy ( ctrl+alt+h ) especially if you’re trying to understand the flow of methods in a class and move between them easily. knowing how to navigate between views and editors with the keyboard helps a lot since you’ll be moving between the call hierarchy view and editors a lot.
what should i use when?
- use next/previous member shortcut if the class is small or you have a good idea of where other methods are in relation to the current method (eg. are they above/below the current method).
- use the quick outline if you don’t know the class too well or there are lots of methods in the class.
- use open declaration if you’re moving between many private methods of the class. it’s normally the fastest way to move to another private method in the class, but only if you’re already positioned in a method that calls it.
from http://eclipseone.wordpress.com/2011/02/21/the-easiest-ways-to-navigate-methods-in-a-class-using-eclipse-keyboard-shortcuts/