This is a WIP community resource, containing contribution from community members.
This guide covers the essential features in VS Code for navigating Java source code efficiently.
Ensure you have followed our guide on Preparing VS Code for Java.
The Explorer view (/ Ctrl+Shift+E
| Cmd+Shift+E
) is the main panel for navigating files and folders in your project. It also contains the Outline view for quick symbol navigation and the Java Projects view for managing your project's structure and dependencies.
The Outline view appears at the bottom of the Explorer view and displays the symbol tree of the currently open file. You can sort the Outline and enable/disable cursor tracking. Errors and warnings are also shown, making it easy to locate issues in the file.
The Java Projects view gives you an overview of your Java projects and their dependencies, and provides quick access to common project management tasks.
The Java Projects view should appear at the bottom of the Explorer view by default. If you do not see it, try clicking the ...
(Views and More Actions...) button at the top right in the EXPLORER title bar and select Projects.
You can search for symbols in the current file or workspace to navigate your code more quickly.
To search for a symbol in the current workspace, press Ctrl+T
and enter the name of the symbol, then select from the list of matches to navigate to its location.
You can also use Quick Open (Ctrl+P
), then enter #
to search the current workspace. Ctrl+T
is simply the shortcut.
To search for a symbol in the current file, Quick Open (Ctrl+P
) and enter @
before entering the name of the symbol, then select from the list of matches to navigate to its location.
You can view or navigate to where a class, method, or variable is defined in your code to understand and trace how different parts of your project are connected.
To view a symbol's definition without leaving your current location, place your cursor on the symbol and press Alt+F12
. Alternatively, right-click on the symbol and select Peek > Peek Definition from the context menu.
To navigate to a symbol's definition, place your cursor on the symbol and press F12
. Alternatively, right-click on the symbol and select Go to Definition from the context menu. If there are multiple definitions, you will be prompted to select the definition that you wish to navigate to.
You can trace class implementations and overriding methods by hovering over the class or method and click Go to Super Implementation to navigate to its parent class or overridden method.
You can view all calls from or to a function to understand the flow of your code and dependencies between functions.
To view the call hierarchy of a function, right-click on the function and select Peek > Peek Call Hierarchy to open in an inline panel, or select Show Call Hierarchy to open in the sidebar.
You can explore the inheritance relationships between classes and interfaces in your code to understand and navigate complex type hierarchies between Java Objects.
To view the call hierarchy of a class or interface, right-click on the class or interface and select Show Type Hierarchy to open in the sidebar.
You can collapse or expand code blocks to focus on relevant sections of your code by clicking the folding icons in the gutter next to the line numbers or by using keyboard shortcuts:
Ctrl+Shift+[
) folds the innermost uncollapsed region at the cursor.Ctrl+Shift+]
) unfolds the collapsed region at the cursor.Ctrl+K Ctrl+L
) folds or unfolds the region at the cursor.Ctrl+K Ctrl+[
) folds the innermost uncollapsed region at the cursor and all regions inside that region.Ctrl+K Ctrl+]
) unfolds the region at the cursor and all regions inside that region.Ctrl+K Ctrl+0
) folds all regions in the editor.Ctrl+K Ctrl+J
) unfolds all regions in the editor.Contributors: John Wong (@Johnwz123)