Code Editing Essentials
The ability to write and modify text and code is a core function of the integrated development environment (IDE). Visual Studio provides many editors tailored to specific file types. Most editors have two views: designer view and code view. All editors share a core set of functionality, but also provide functionality specific to the file you are working with.
For example, if you open a Visual C++ Windows Form for edit, the C++ Form Editor opens in designer view as the default editor for this file. If you open a Visual Basic Windows Form, the Visual Basic Form Editor opens in designer view as the default editor for it. These two editors look similar but are in fact two different editors. Use this topic to become familiar with the features and functionality of editors in Visual Studio. For more information about the features available in the core editor, see.
This topic does not discuss resource editors. For more information, see.
A generic term that refers to all code, text, and markup language editors available in the IDE. In past releases, the term "Code and Text Editor" was used.
- Code view
A mode of the editor where you can modify text and code in files. Sometimes referred to as "Source view". Available in all editors.
- Indicator margin
The gray channel on the left edge of the editor in the Code view where debugging, bookmark, and error icons appear.
- Designer view
A mode of the editor where you create the layout and visual appearance of portions of an application. Not available in all editors.
- Design surface
A generic term that refers to the visual area where you add and move controls and other elements. Applies to Windows Forms, HTML pages, ASPX pages, and any other file that includes Designer view when editing.
A generic term that refers to the various icons, such as breakpoints, bookmarks, etc., that display in the indicator margin.
Using the Editor
Different tools and features are available in the editor depending on which view of the editor you are using as well as the type of file you are editing.
Designer view allows you to create the visual layout for Windows Forms, HTML pages, and ASPX files, among others. You can add controls, edit control properties, and position controls all from designer view. Some common tools used in designer view include the following:
Lists the controls and other items that can be added to the design surface.
Provides an outline view of the controls, HTML elements, and scripts on the current design surface.
Lists the properties, such as Text, that can be edited for the selected control, form, or other item on the design surface.
Code view is where you write and manage the code that runs the application. You can set breakpoints for debugging, collapse sections of code to increase readability, and use aids to write code faster. Some common features used in code view include the following:
IntelliSense provides in place language reference prompts that allow you to code more quickly. These prompts include the display of a list of appropriate methods as you type, the display of parameter and declaration information, and others. All programming languages support IntelliSense, though some programming languages have more IntelliSense features than others. For more information, see.
IntelliSense Code snippets allow you to insert pre-written code directly into your file. These code snippets can originate from Microsoft or can be code you or others have created. Currently, Visual C++ and HTML do not support IntelliSense code snippets. For more information, see.
You can set breakpoints in the indicator margin of the editor and then use the Visual Studio Debugger to walk through your application so you can solve any logic errors you encounter. You also can turn on line numbers to better help locate compile errors. For information about indicator margin icons, see. For more information about debugging, see .
Use Navigate Forward and Navigate Backward on the View menu to move among recently viewed sections of code within a single file or between recently viewed files in the editor.
Use the Go to Definition command to navigate to the procedure for a method or a variable definition. For example, if you define a procedure called MyProc(), and then later in your code make a call to MyProc(), you can navigate directly to the procedure for this method using Go to Definition.
Use Bookmarks to mark lines of code within large files so you can quickly navigate to those sections of code in the editor. For more information, see.
Use the various find features, such as Incremental Search and Find in Files, to navigate within a file and across files. For more information, see.
The editor supports wrapping lines of code to fit the current window size as well as numbering each line of code. For more information, seeand .
You also can hide regions of code so that you only see the regions you need to work in. For more information, see.
Customizing the Editor
You can set preferences for certain features and apply these preferences to all editors or individual editors using the Options dialog box. Some changes, such as font family and size, always are applied globally.
Global versus Language-specific Editor Customizations
Certain settings related to editors, such as word wrap, line numbers, and indenting, can be applied automatically to all editors. You also can change the settings for a single programming language or markup editor without affecting other editors. Global editor settings can be found on certain pages in the Text Editor section of the Options dialog box:
All other nodes under Text Editor contain options specific to a particular programming or markup language. Making a change in one of those nodes affects only the editors for the selected programming or markup language. For more information, see.
You can change the font family and font size that is used in Code view of all editors, as well as text colors, in the. The Show settings for drop-down list contains the following entries related to text displayed in editors:
Making a change to any one of these areas affects all editors in Visual Studio. For more information, see.