You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/get-started/csharp/tutorial-editor.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -203,7 +203,7 @@ The code block collapses to just the first line, followed by an ellipsis (`...`)
203
203
204
204
:::monikerrange="<=vs-2019"
205
205
206
-
TheVisualStudioeditormakesiteasytoinspectthedefinitionofatype, method, etc. Onewayistonavigatetothefilethatcontainsthedefinition, for example by choosing **Go to Definition** or pressing **F12** anywhere the symbol is referenced. An even quicker way that doesn't move your focus away from the file you're working in is to use [Peek Definition](../../ide/go-to-and-peek-definition.md#peek-definition). Let's peek at the definition of the `string` type.
206
+
TheVisualStudioeditormakesiteasytoinspectthedefinitionofatype, method, etc. Onewayistonavigatetothefilethatcontainsthedefinition, for example by choosing **Go to Definition** or pressing **F12** anywhere the symbol is referenced. An even quicker way that doesn't move your focus away from the file you're working in is to use [Peek Definition](../../ide/go-to-and-peek-definition.md#peek-at-a-definition). Let's peek at the definition of the `string` type.
@@ -217,7 +217,7 @@ The Visual Studio editor makes it easy to inspect the definition of a type, meth
217
217
218
218
::: moniker range=">=vs-2022"
219
219
220
-
The Visual Studio editor makes it easy to inspect the definition of a type, method, or variable. One way is to go to the definition, in whichever file has it, by choosing **Go to Definition** or pressing **F12** anywhere a symbol is referenced. An even quicker way that doesn't move your focus away from the code you're working on is to use [Peek Definition](../../ide/go-to-and-peek-definition.md#peek-definition).
220
+
The Visual Studio editor makes it easy to inspect the definition of a type, method, or variable. One way is to go to the definition, in whichever file has it, by choosing **Go to Definition** or pressing **F12** anywhere a symbol is referenced. An even quicker way that doesn't move your focus away from the code you're working on is to use [Peek Definition](../../ide/go-to-and-peek-definition.md#peek-at-a-definition).
221
221
222
222
Let's peek at the definition of the `string` type.
Copy file name to clipboardExpand all lines: docs/get-started/tutorial-editor.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -247,7 +247,7 @@ The code block collapses to just the first line, followed by an ellipsis (`...`)
247
247
248
248
:::monikerrange="<=vs-2019"
249
249
250
-
TheVisualStudioeditormakesiteasytoinspectthedefinitionofatype, method, etc. Onewayistonavigatetothefilethatcontainsthedefinition, for example by choosing **Go to Definition** anywhere the symbol is referenced. An even quicker way that doesn't move your focus away from the file you're working in is to use [Peek Definition](../ide/go-to-and-peek-definition.md#peek-definition). Let's peek at the definition of the `string` type.
250
+
TheVisualStudioeditormakesiteasytoinspectthedefinitionofatype, method, etc. Onewayistonavigatetothefilethatcontainsthedefinition, for example by choosing **Go to Definition** anywhere the symbol is referenced. An even quicker way that doesn't move your focus away from the file you're working in is to use [Peek Definition](../ide/go-to-and-peek-definition.md#peek-at-a-definition). Let's peek at the definition of the `string` type.
@@ -261,7 +261,7 @@ The Visual Studio editor makes it easy to inspect the definition of a type, meth
261
261
262
262
::: moniker range=">=vs-2022"
263
263
264
-
The Visual Studio editor makes it easy to inspect the definition of a type, method, or variable. One way is to go to the definition, in whichever file has it, by choosing **Go to Definition** or by selecting the **F12** key anywhere a symbol is referenced. An even quicker way that doesn't move your focus away from the code you're working on is to use [Peek Definition](../ide/go-to-and-peek-definition.md#peek-definition).
264
+
The Visual Studio editor makes it easy to inspect the definition of a type, method, or variable. One way is to go to the definition, in whichever file has it, by choosing **Go to Definition** or by selecting the **F12** key anywhere a symbol is referenced. An even quicker way that doesn't move your focus away from the code you're working on is to use [Peek Definition](../ide/go-to-and-peek-definition.md#peek-at-a-definition).
265
265
266
266
Let's peek at the definition of the `string` type.
Copy file name to clipboardExpand all lines: docs/get-started/visual-basic/tutorial-editor.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -198,7 +198,7 @@ The code block collapses to just the first line, followed by an ellipsis (`...`)
198
198
199
199
::: moniker range="<=vs-2019"
200
200
201
-
The Visual Studio editor makes it easy to inspect the definition of a type, method, etc. One way is to navigate to the file that contains the definition, for example by choosing **Go to Definition** anywhere the symbol is referenced. An even quicker way that doesn't move your focus away from the file you're working in is to use [Peek Definition](../../ide/go-to-and-peek-definition.md#peek-definition). Let's peek at the definition of the `String` type.
201
+
The Visual Studio editor makes it easy to inspect the definition of a type, method, etc. One way is to navigate to the file that contains the definition, for example by choosing **Go to Definition** anywhere the symbol is referenced. An even quicker way that doesn't move your focus away from the file you're working in is to use [Peek Definition](../../ide/go-to-and-peek-definition.md#peek-at-a-definition). Let's peek at the definition of the `String` type.
202
202
203
203
1. Right-click on the word `String` and choose **Peek Definition** from the content menu. Or, press **Alt**+**F12**.
204
204
@@ -212,7 +212,7 @@ The Visual Studio editor makes it easy to inspect the definition of a type, meth
212
212
213
213
::: moniker range=">=vs-2022"
214
214
215
-
The Visual Studio editor makes it easy to inspect the definition of a type or class member. One way is to navigate to the file that contains the definition, for example by choosing **Go to Definition** anywhere the symbol is referenced. An even quicker way that doesn't move your focus away from the file you're working in is to use [Peek Definition](../../ide/go-to-and-peek-definition.md#peek-definition). Let's peek at the definition of the `String` type.
215
+
The Visual Studio editor makes it easy to inspect the definition of a type or class member. One way is to navigate to the file that contains the definition, for example by choosing **Go to Definition** anywhere the symbol is referenced. An even quicker way that doesn't move your focus away from the file you're working in is to use [Peek Definition](../../ide/go-to-and-peek-definition.md#peek-at-a-definition). Let's peek at the definition of the `String` type.
216
216
217
217
1. Right-click on the word `String` and choose **Peek Definition** from the content menu. Or, press **Alt**+**F12**.
title: View type definitions with Go To and Peek features
3
3
description: Explore the Go To Definition and Peek Definition features that enable you to easily view the definition of a type or member in Visual Studio.
4
-
ms.date: 01/10/2018
5
-
ms.topic: conceptual
4
+
ms.date: 08/21/2024
5
+
ms.topic: concept-article
6
6
helpviewer_keywords:
7
7
- code editor, view definition
8
8
- go to definition
@@ -13,64 +13,85 @@ author: ghogen
13
13
ms.author: ghogen
14
14
manager: mijacobs
15
15
ms.subservice: general-ide
16
+
17
+
#customer intent: As a developer, I want to use the Go To and Peek features in Visual Studio, so I can easily view type and member source definitions for my code.
16
18
---
19
+
17
20
# View type and member definitions
18
21
19
-
Developers often need to view the source code definitions for types or class members they use in their code. In Visual Studio, the **Go To Definition** and **Peek Definition** features enable you to easily view the definition of a type or member. If the source code is not available, metadata is displayed instead.
22
+
Developers often need to view the source code definitions for types or class members they use in their code. In Visual Studio, the **Go To Definition** and **Peek Definition** features let you easily view the definition of a type or member. If the source code isn't available, Visual Studio shows the metadata instead.
20
23
21
-
## Go To Definition
24
+
## Go to a definition
22
25
23
-
The **Go To Definition** feature navigates to the source of a type or member, and opens the result in a new tab. If you are a keyboard user, place your text cursor somewhere inside the symbol name and press **F12**. If you are a mouse user, either select **Go To Definition** from the right-click menu or use the **Ctrl-click** functionality described in the following section.
26
+
When you use the **Go To Definition** feature, Visual Studio locates the source code for the selected type or member. If the source code is in a different file, the file opens in a new window. Visual Studio changes the current focus to highlight the relevant entry.
24
27
25
-
### Ctrl-click Go To Definition
28
+
:::image type="content" source="./media/go-to-definition-new-window.png" border="false" alt-text="Screenshot that shows how Go To Definition opens the source file for the selected symbol in a new window." lightbox="./media/go-to-definition-new-window.png":::
26
29
27
-
**Ctrl**+**click** is a shortcut for mouse users to quickly access **Go To Definition**. Symbols become clickable when you press **Ctrl** and hover over the type or member. To quickly navigate to the definition of a symbol, press the **Ctrl** key and then click on it. It's that easy!
30
+
There are several ways you can access **Go To Definition**:
28
31
29
-

32
+
- Position the cursor inside the symbol name and use the **F12** function key
30
33
31
-
You can change the modifier key for mouse-click **Go To Definition** by going to **Tools** > **Options** > **Text Editor** > **General**, and selecting either **Alt** or **Ctrl**+**Alt** from the **Use modifier key** drop-down. You can also disable mouse-click **Go To Definition** by unchecking the **Enable mouse click to perform Go To Definition** checkbox.
34
+
- Right-click the symbol name and select **Go To Definition**
32
35
33
-

36
+
- Use the **Ctrl**+**Click** keyboard/mouse shortcut on the symbol name
34
37
35
-
##Peek Definition
38
+
### Change action shortcut
36
39
37
-
The **Peek Definition** feature lets you preview the definition of a type without leaving your current location in the editor. If you are a keyboard user, place your text cursor somewhere inside the type or member name and press **Alt + F12**. If you are a mouse user, you can select **Peek Definition**from the right-click menu.
40
+
You can enable or disable the **Ctrl**+**Click** shortcut for **Go To Definition** with the **Enable mouse click to perform Go To Definition** option under **Tools** > **Options** > **Text Editor**> **General**.
38
41
39
-
To enable **Ctrl**+**click** functionality, go to**Tools** > **Options** > **Text Editor** >**General**. Select the option **Open definition in peek view** and click **OK** to close the **Options** dialog box.
42
+
To change the modifier key for the shortcut, expand the**Use modifier key** dropdown list and select**Ctrl** (default), **Alt**, or **Ctrl**+**Alt**:
40
43
41
-

44
+
:::image type="content" source="./media/editor-options-go-to-definition.png" border="false" alt-text="Screenshot of the Text Editor options for the Go To Definition feature, including the 'Use modifier key' setting.":::
42
45
43
-
Then, press **Ctrl** (or whichever modifier key is selected in **Options**), and click on the type or member.
The **Peek Definition** feature lets you preview the definition of a type without changing the focus from your current file in the editor. Visual Studio opens a condensed **Peek** view window for the source file in place with your current file. You can change the size of the **Peek** view window to see more of the source definition:
46
49
47
-
If you peek another definition from the popup window, you start a breadcrumb path that you can navigate using the circles and arrows that appear above the popup.
50
+
:::image type="content" source="./media/peek-definition-view-window.png" border="false" alt-text="Screenshot that shows how Peek Definition opens the source for the selected symbol in a peek view window within the current view." lightbox="./media/peek-definition-view-window.png":::
48
51
49
-
For more information, see [How to: View and edit code by using Peek Definition (Alt+F12)](how-to-view-and-edit-code-by-using-peek-definition-alt-plus-f12.md).
52
+
When you close the **Peek** view window, your current code file remains open in the editor.
50
53
51
-
## View metadata as source code (C#)
54
+
There are several ways you can access **Peek Definition**:
55
+
56
+
- Position the cursor inside the symbol name and select **Alt**+**F12** function key
57
+
58
+
- Right-click the symbol name and select **Peek Definition**
59
+
60
+
- Use the **Ctrl**+**Click** keyboard/mouse shortcut on the symbol name
61
+
62
+
### Change action shortcut
52
63
53
-
When you view the definition of C# types or members whose source code is not available, their metadata is displayed instead. You can see the declarations of the types and members, but not their implementations.
64
+
You can configure the **Ctrl**+**Click** keyboard/mouse shortcut for **Go To Definition** to open the source code file in **Peek** view. Use the **Open definition in peek view** option under **Tools** > **Options** > **Text Editor** > **General**.
54
65
55
-
When you run the **Go To Definition** or **Peek Definition** command for an item whose source code is unavailable, a tabbed document that contains a view of that item's metadata, displayed as source code, appears in the code editor. The name of the type, followed by **[from metadata]**, appears on the document's tab.
66
+
:::image type="content" source="./media/editor-options-peek-view.png" border="false" alt-text="Screenshot of the Text Editor options for the Peek Definition feature.":::
67
+
68
+
### Use breadcrumb path for multiple files
69
+
70
+
If you peek another definition from the open **Peek** view window, you start a breadcrumb path. You can peek forward and backward along the path by using the circles and arrows above the **Peek** view window:
71
+
72
+
:::image type="content" source="./media/peek-backward-breadcrumb.png" border="false" alt-text="Screenshot that shows the breadcrumb path of open source files for Peek Definition and the option to peek backward." lightbox="./media/peek-backward-breadcrumb.png":::
73
+
74
+
When you close the **Peek** view window, Visual Studio closes all open files in the breadcrumb path. For more information, see [View and edit code by using Peek Definition (Alt+F12)](how-to-view-and-edit-code-by-using-peek-definition-alt-plus-f12.md).
75
+
76
+
## View metadata as source code (C#)
56
77
57
-
For example, if you run the **Go To Definition** command for <xref:System.Console>, metadata for <xref:System.Console> appears in the code editor as C# source code. The code resembles its declaration, but does not show an implementation.
78
+
When you try to look at the definition for a C# type or member and the source code isn't available, Visual Studio shows metadata for the symbol instead. You can see the declarations of the types and members, but not their implementations. The tab label for the window includes the symbol name followed by **[from metadata]**:
58
79
59
-

80
+
:::image type="content" source="./media/view-source-metadata.png" border="false" alt-text="Screenshot that shows how Visual Studio displays metadata only when the source code for the selected symbol isn't available." lightbox="./media/view-source-metadata.png":::
60
81
61
82
> [!NOTE]
62
-
> When you try to run the **Go To Definition** or **Peek Definition** command for types or members that are marked as internal, Visual Studio does not display their metadata as source code, regardless of whether the referencing assembly is a friend or not.
83
+
> If you try to look at the definition for an *internal* type or member, Visual Studio doesn't display the metadata as source code, regardless of whether the referencing assembly is a *friend*. For more information, see [Friend assemblies](/dotnet/standard/assembly/friend).
63
84
64
-
### View decompiled source definitions instead of metadata (C#)
85
+
### View decompiled source definitions (C#)
65
86
66
-
You can set an option to see decompiled source code when you view the definition of a C# type or member whose source code is unavailable. To turn on this feature, choose **Tools** > **Options**from the menu bar. Then, expand **Text Editor** > **C#** > **Advanced**, and select **Enable navigation to decompiled sources**.
87
+
When the source code for the selected C# symbol isn't unavailable, you can set an option to see decompiled source definitions rather than metadata. Use the **Enable navigation to decompiled sources** option under **Tools** > **Options**> **Text Editor** > **C#** > **Advanced**.
67
88
68
-

89
+
:::image type="content" source="./media/view-source-decompiled.png" border="false" alt-text="Screenshot that shows how Visual Studio displays decompiled source code when the definition for the selected symbol isn't available." lightbox="./media/view-source-decompiled.png":::
69
90
70
91
> [!NOTE]
71
-
> Visual Studio reconstructs method bodies using ILSpy decompilation. The first time you access this feature, you must agree to a legal disclaimer regarding software licensing and copyright and trademark laws.
92
+
> Visual Studio reconstructs method bodies by using [ILSpy](https://github.com/icsharpcode/ILSpy) decompilation. The first time you access this feature, you must agree to a legal disclaimer regarding software licensing and copyright and trademark laws.
72
93
73
94
## Related content
74
95
75
-
-[Navigate code](../ide/navigating-code.md)
76
-
-[How to: View and edit code by using Peek Definition (Alt+F12)](how-to-view-and-edit-code-by-using-peek-definition-alt-plus-f12.md)
96
+
-[Navigate your code in Visual Studio](../ide/navigating-code.md)
97
+
-[View and edit code by using Peek Definition (Alt+F12)](how-to-view-and-edit-code-by-using-peek-definition-alt-plus-f12.md)
Copy file name to clipboardExpand all lines: docs/ide/reference/options-text-editor-advanced.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ Selected by default, this option enables the editor to suggest possible completi
53
53
54
54
## Click to peek in margin
55
55
56
-
The **Single click** setting is selected by default. The settings you choose from allow you to customize how Peek Definition works when you use it to display the differences between Git commits. You can change the default **Single click** setting to **Double click**, or you can select **None** to turn off the [Peek Difference UI](../../version-control/git-line-staging.md#peek-difference-support).
56
+
The **Single click** setting is selected by default. The settings you choose from allow you to customize how Peek Definition works when you use it to display the differences between Git commits. You can change the default **Single click** setting to **Double click**, or you can select **None** to turn off the [Peek Difference UI](../../version-control/git-line-staging.md#view-staged-changes-with-peek-difference).
0 commit comments