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 Code and Text Editor.
This topic does not discuss resource editors. For more information, see Working with Resource Files.
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 Using IntelliSense.
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 Creating and Using IntelliSense Code Snippets.
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 How to: Debug Code in the Editor. For more information about debugging, see Debugging in Visual Studio.
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 Bookmark Window.
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 Finding and Replacing.
The editor supports wrapping lines of code to fit the current window size as well as numbering each line of code. For more information, see How to: Manage Word Wrap in the Editorand How to: Display Line Numbers in the Editor.
You also can hide regions of code so that you only see the regions you need to work in. For more information, see How to: Outline and Hide Code.
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 Setting Editor Options.
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 Fonts and Colors, Environment, Options Dialog Box. 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 How to: Change the Font Face, Size, and Colors Used in the Editor.