The Eclipse IDE makes searching for code very easy, both with built-in functionality and third-party plugins such as Ctrlflow Code Search Professional. This is even more true when using the various shortcuts, which this post will introduce you to.
When searching for code, developers typically want to either find locations where, e.g., a method is declared or used, or examples of how it is used. Eclipse’s built-in search functionality serves us well in the first case, but can be cumbersome in the second case, where Ctrlflow Code Search Professional shines.
Eclipse Shortcuts Overview
You can get a list of all currently applicable shortcuts using Ctrl+Shift+L, but the General > Keys preference page goes further: Here, you can search for, change, or create key bindings for any command.
Shortcuts for Finding Locations
You likely already know about the standard text search Ctrl+F to search through the current file, but Ctrl+K and Ctrl+Shift+K allow you to cycle through each occurrence of the currently selected text. Use Alt+Ctrl+G for a text search across the entire workspace.
To get a filterable list of declarations in the current file, use Ctrl+O.
When you have a Java element selected, use Ctrl+G to find all declarations of the same name in your workspace. When you have selected a type, use Ctrl+T to show its subtypes. Use this shortcut a second time to see the types’ supertypes.
Ctrl+Shift+T gives you a filterable list of all types declared in your workspace. Similarly, Ctrl+Shift+R gives you a filterable list of all files in your workspace.
When you have a Java element selected, press Ctrl+Shift+U to search for references to it within the current file, or Ctrl+Shift+G to search for references in the entire workspace.
Shortcuts for Finding Examples
To find code examples using Eclipse, you typically have to perform a search for a declaration or reference and then open each result in an editor. This quickly becomes cumbersome.
Using Ctrlflow Code Search Professional’s Ctrl+Alt+Shift+G shortcut while a Java element is selected will perform multiple lightning-fast searches at once. Beyond finding declarations and references, these searches will show you examples of how the element is used in the workspace. Moreover, you do not need to open any of the results in your editor; the preview allows you to immediately examine each result in context.
You can also the Code Search view’s search bar to instantly search for references, declarations, and String literals using any text search terms.
Last but not least, you can use Ctrlflow Code Search Professional catalogs to extend the scope of your search beyond your workspace, getting instant access to code examples for popular libraries like JavaFX, Spring, Vaadin, and the Eclipse platform.
|Search Name||Search Scope||Search Target||Windows/Linux Key Combinations||Mac Key Combinations|
|Find and Replace||Current File||Text||Ctrl+F||Cmd+F|
|Quick Outline||Current File||Declarations||Ctrl+O||Cmd+O|
|Show Occurrences in File Quick Menu||Current File||References||Ctrl+Shift+U||Cmd+Shift+U|
|Find Text in Workspace||Workspace||Text||Ctrl+Alt+G||Cmd+Alt+G|
|References in Workspace||Workspace||References||Ctrl+Shift+G||Cmd+Shift+G|
|Declaration in Workspace||Workspace||Declarations||Ctrl+G||Cmd+G|
|Workspace + catalogs||Declarations, References||Ctrl+Alt+Shift+G||Cmd+Alt+Shift+G|
|Workspace + catalogs||Declarations, References||Ctrl+Alt+Shift+H||Cmd+Alt+Shift+H|
|Open Search Dialog||Workspace||Text, Declarations, References||Ctrl+H||Cmd+H|
|Show Key Assist||NA||NA||Ctrl+Shift+L||Cmd+Shift+L|