Last updated: Apr 6, 2024
Reading time·5 min
To go to a definition in VS Code:
F12
keyboard shortcut.Alternatively, you can right-click on a reference and select Go to Definition.
Here is a short clip that demonstrates the process.
You can also use the Command Palette to go to a definition:
Set your cursor on the reference.
Press:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.Alternatively:
Ctrl
(or Alt
) and click on the reference.Cmd
(or Option
) and click on the reference.Ctrl
(or Alt
) and click on the reference.When you press and hold Ctrl
(or Cmd
) and hover over a symbol, it becomes
clickable.
You can also open the definition to the side:
Set your cursor on the reference.
Press:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.If you need to go back to the reference:
Alt
+ Left
arrow key.Ctrl
+ -
.Ctrl
+ Alt
+ -
.You can also view the Go Back keyboard shortcut for your operating system in this table in the docs.
Alternatively, you can use the Command Palette:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.You can also view the keyboard shortcut for your operating system directly in the Command Palette.
If you need to change the keyboard shortcut:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.Enter
.If you need to peek a definition:
Right-click on a reference.
Click on Peek and then select Peek definition.
The definition opens in Peek mode, directly in the current file.
You can also use the Command Palette to open a definition in peek mode:
Select the reference.
Press:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.There is a setting that opens definitions in peek mode by default.
If you need to disable or enable the setting:
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.You can also open the settings screen by pressing Ctrl
+ ,
on Windows and
Linux or Cmd
+ ,
on macOS.
If you need to go to the implementation of the function or class:
Here is a short clip that demonstrates using the action.
When using the Go to Source Definition action, we jump to the location where
the function or class is implemented (e.g. in a JavaScript file in
node_modules
).
You can also use the action via the Command Palette:
Select the reference.
Press:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.There is also a Go to Type definition action if you need to jump to the type definition of the symbol:
Here is a short clip that demonstrates the process.
You can also use the Command Palette to trigger the Go to Type Definition action:
Select the reference.
Press:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.You can learn more about the related topics by checking out the following tutorials: