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/tutorial-editor.md
+22-19Lines changed: 22 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Introduction to editing in the code editor
3
3
description: Use the code editor in Visual Studio to add code to a file, and also how to write code, navigate to it, and refactor it.
4
-
ms.date: 1/23/2025
4
+
ms.date: 7/25/2025
5
5
ms.subservice: general-ide
6
6
ms.custom: vs-acquisition
7
7
ms.topic: tutorial
@@ -14,7 +14,7 @@ dev_langs:
14
14
---
15
15
# Learn to use the code editor
16
16
17
-
In this 10-minute introduction to the code editor in Visual Studio, we'll add code to a file to look at some of the ways that Visual Studio makes writing, navigating, and understanding code easier.
17
+
In this introduction to the Visual Studio code editor, you’ll add code to a file and explore how Visual Studio helps make writing, navigating, and understanding code easier.
18
18
19
19
::: moniker range="vs-2019"
20
20
@@ -33,14 +33,15 @@ This article assumes you're already familiar with a programming language. If you
33
33
34
34
::: moniker range=">=vs-2022"
35
35
36
-
> [!TIP]
37
-
> To follow along with this article, make sure you have the C# settings selected for Visual Studio. For information about selecting settings for the integrated development environment (IDE), see [Select environment settings](csharp/visual-studio-ide.md#select-environment-settings).
36
+
## Prerequisites
37
+
38
+
- Visual Studio with C# development settings configured. To configure settings, see [Select environment settings](csharp/visual-studio-ide.md#select-environment-settings).
38
39
39
40
::: moniker-end
40
41
41
42
## Create a new code file
42
43
43
-
Start by creating a new file and adding some code to it.
44
+
Create a new file and add some code to it.
44
45
45
46
::: moniker range="vs-2019"
46
47
@@ -64,7 +65,7 @@ Start by creating a new file and adding some code to it.
64
65
65
66
1. In the **New File** dialog box, under the **General** category, select **C# Class**, and then select **Open**.
66
67
67
-
A new file opens in the editor with the skeleton of a C# class.
68
+
A new file opens in the editor with a basic C# class structure.
68
69
69
70
:::image type="content" source="media/vs-2022/tutorial-editor.png" alt-text="Screenshot of a C# code file in Visual Studio 2022.":::
70
71
@@ -86,7 +87,7 @@ Let's use Copilot to generate code suggestions:
86
87
1. GitHub Copilot generates a code suggestion for you. The suggested implementation shows in gray text.
87
88
1. To accept the suggestion, select **Tab**.
88
89
89
-
:::image type="content" source="media/vs-2022/tutorial-editor/github-copilot-suggestions-visual-studio.gif" alt-text="Animated screenshot that shows the code suggestions generated by GitHub Copilot for the user comment." lightbox="media/vs-2022/tutorial-editor/github-copilot-suggestions-visual-studio.gif":::
90
+
:::image type="content" source="media/vs-2022/tutorial-editor/github-copilot-suggestions-visual-studio.gif" alt-text="Animated screenshot that shows the code suggestions generated by GitHub Copilot for the user comment." lightbox="media/vs-2022/tutorial-editor/github-copilot-suggestions-visual-studio.gif":::
90
91
91
92
Let's use Copilot Chat to submit a coding-related question as a prompt:
92
93
@@ -104,15 +105,15 @@ Let's use Copilot Chat to submit a coding-related question as a prompt:
104
105
105
106
GitHub Copilot is powered by AI, so surprises and mistakes are possible. For more information, see [GitHub Copilot FAQs](https://github.com/features/copilot#faq).
106
107
107
-
Get started with [GitHub Copilot in Visual Studio](../ide/visual-studio-github-copilot-install-and-states.md). Note that it requires Visual Studio 2022 version 17.8 or later.
108
+
Get started with [GitHub Copilot in Visual Studio](../ide/visual-studio-github-copilot-install-and-states.md).
108
109
109
110
::: moniker-end
110
111
111
112
## Use code snippets
112
113
113
-
Visual Studio provides useful *code snippets* that you can use to quickly and easily generate commonly used code blocks. [Code snippets](../ide/code-snippets.md) are available for different programming languages including C#, Visual Basic, and C++.
114
+
Visual Studio provides useful code snippets that you can use to quickly generate commonly used code blocks. Code snippets are available for several programming languages, including C#, Visual Basic, and C++.
114
115
115
-
Let's add the C# `void Main` snippet to our file.
116
+
Now add the C# `void Main` snippet to your file.
116
117
117
118
::: moniker range="<=vs-2019"
118
119
@@ -144,7 +145,7 @@ The available code snippets vary for different programming languages. You can lo
144
145
145
146
You'll see the `static void Main()` method signature get added to the file. The [Main()](/dotnet/csharp/programming-guide/main-and-command-args/) method is the entry point for C# applications.
146
147
147
-
Available code snippets vary for different programming languages. You can look at the available code snippets for your language by choosing**Edit** > **IntelliSense** > **Insert Snippet** or by selecting the **Ctrl**+**K**, **Ctrl**+**X** keys, and then choosing the folder for your programming language. For C#, the snippet list looks like this:
148
+
Available code snippets vary by programming language. To view the available code snippets for your language, go to**Edit** > **IntelliSense** > **Insert Snippet** or select **Ctrl**+**K**, **Ctrl**+**X** keys, then select the folder for your programming language. For C#, the code snippet list looks like this:
148
149
149
150
:::image type="content" source="media/vs-2022/tutorial-code-snippet-list.png" alt-text="Screenshot of an IntelliSense pop-up for a C# code snippet list.":::
150
151
@@ -194,7 +195,7 @@ The toolbar, which is the row of buttons under the menu bar in Visual Studio, ca
:::imagetype="content"source="media/vs-2022/tutorial-editor-toolbar.png"alt-text="Screenshot of the Text Editor toolbar in Visual Studio 2022.":::
200
201
@@ -225,13 +226,13 @@ Let's comment out some code.
225
226
selectword;
226
227
```
227
228
228
-
1. We're not using the `moreWords` variable, but we might use it later so we don'twanttodeleteit. Instead, we'll comment out those lines. Select the entire definition of `moreWords` down to the closing semicolon, and then choose the **Comment out the selected lines** button on the Text Editor toolbar. If you prefer to use the keyboard, select **Ctrl**+**K**, **Ctrl**+**C**.
229
+
1. The`moreWords` variableisn't currently being used, but you might use it later, so instead of deleting it, you can comment out those lines. Select the entire definition of `moreWords` down to the closing semicolon, and then select the **Comment out the selected lines** button on the Text Editor toolbar, or select **Ctrl**+**K**, **Ctrl**+**C**.
229
230
230
231
:::imagetype="content"source="media/vs-2022/tutorial-comment-out.png"alt-text="Screenshot of the Comment out button in the Text Editor toolbar in Visual Studio 2022.":::
231
232
232
233
TheC# commentcharacters `//` are added to the beginning of each selected line to comment out the code.
:::imagetype="content"source="media/vs-2022/tutorial-uncomment.png"alt-text="Screenshot of the Uncomment button in the Text Editor toolbar in Visual Studio 2022.":::
237
238
@@ -251,11 +252,11 @@ The code block collapses to just the first line, followed by an ellipsis (`...`)
251
252
252
253
:::monikerrange=">=vs-2022"
253
254
254
-
Wedon't want to see the empty [constructor](/dotnet/csharp/programming-guide/classes-and-structs/constructors) that was generated for `Class1`, so to unclutter our view of the code, let'scollapseit. Choosethesmallgrayboxwiththeminussigninsideitinthemarginofthefirstlineoftheconstructor. Or, ifyouprefertousethekeyboard, placethecursoranywhereintheconstructorcodeandselectthe**Ctrl**+**M**, **Ctrl**+**M**keys.
255
+
Ifyoudon't want to see the empty [constructor](/dotnet/csharp/programming-guide/classes-and-structs/constructors) that was generated for `Class1`, you can collapse it to unclutter your view of the code. Select the caret sign in the margin of the first line of the constructor. Or, if you prefer to use the keyboard, place the cursor anywhere in the constructor code and select the **Ctrl**+**M**, **Ctrl**+**M** keys.
255
256
256
-
:::imagetype="content"source="media/vs-2022/tutorial-collapse.png"alt-text="Screenshot of the Outlining collapse button in the Text Editor toolbar in Visual Studio 2022.":::
257
+
:::imagetype="content"source="media/vs-2022/tutorial-collapse-down-arrow.png"alt-text="Screenshot of the Outlining collapse button in the Text Editor toolbar.":::
257
258
258
-
Thecodeblockcollapsestojustthefirstline, followedbyanellipsis (`...`). Toexpandthecodeblockagain, selectthesamegrayboxthatnowhasaplussigninit, orselect**Ctrl**+**M**, **Ctrl**+**M**again. Thisfeatureiscalled [Outlining](../ide/outlining.md) andisespeciallyuseful when you're collapsing long methods or entire classes.
259
+
Thecodeblockcollapsestojustthefirstline, followedbyanellipsis (`...`). Toexpandthecodeblockagain, selectthecaretsign(`>`), orselect**Ctrl**+**M**, **Ctrl**+**M**again. Thisfeatureiscalled [Outlining](../ide/outlining.md) andisespeciallyuseful when you're collapsing long methods or entire classes.
259
260
260
261
:::moniker-end
261
262
@@ -285,7 +286,7 @@ Let's peek at the definition of the `string` type.
285
286
286
287
A pop-up window appears with the definition of the `String` class. You can scroll within the pop-up window, or even peek at the definition of another type from the peeked code.
287
288
288
-
:::image type="content" source="media/vs-2022/tutorial-peek-definition.png" alt-text="Screenshot of the Peek definition window in Visual Studio 2022.":::
289
+
:::image type="content" source="media/vs-2022/tutorial-symbol-peek-definition.png" alt-text="Screenshot of the Peek definition window in Visual Studio.":::
289
290
290
291
1. Close the peek definition window by choosing the small box with an "x" at the top right of the pop-up window.
291
292
@@ -303,7 +304,7 @@ Let's peek at the definition of the `string` type.
303
304
foreach (string str in qu
304
305
```
305
306
306
-
You'll see IntelliSense show you **Quick Info** about the `query` symbol.
307
+
You see IntelliSense show you **Quick Info** about the `query` symbol.
307
308
308
309

309
310
@@ -336,6 +337,8 @@ Let's add a line of code to print out the ordered strings to the console window,
336
337
337
338
:::imagetype="content"source="media/vs-2022/tutorial-intellisense-completion-list.png"alt-text="Screenshot of an IntelliSense word completion pop-up in Visual Studio 2022.":::
338
339
340
+
Ifyou're signed in with a GitHub account that has a Copilot subscription, you'llalsoseecodesuggestionsappearingraytext.
0 commit comments