Formatting (General) page General settings When you change a setting by selecting a radio button or check box, the preview window updates to show the effect of the new setting. The preview window shows an example of the selected option. To use the preview window, select a formatting option. When keeping tabs, Visual Studio may still insert some spaces to achieve the correct alignments.The Indentation, New Lines, Spacing, and Wrapping subpages each display a preview window at the bottom that shows the effect of each option. The radio buttons allow you to specify whether pressing the tab key inserts only spaces or that the tab character should be retained if possible. The values provided specifies the number of spaces that will be used in each case. The first two settings allow you to specify the standard size of tabs and indents. The tab section of the tab settings allows you to modify the behaviour of the tab key and automatic indentation. Each has its advantages and drawbacks as described earlier. Indentation is achieved in text files by adding tab or space characters. The actual indentation changes according to the language in use and its typical coding conventions.
VISUAL STUDIO FORMAT DOCUMENT SPACES CODE
However, if the previous line started a new code block, closed an existing block or was a code structure such as a loop or a conditional statement, the indentation is modified to highlight that structure. In most cases this is similar to block indentation. The Smart setting instructs Visual Studio to apply indentation according to the code on the previous line. When Enter is pressed, the cursor moves to the next line and uses the same initial indentation as the line it just left. With the Block option selected, Visual Studio provides simple indenting. When you press the Enter key, the cursor is moved to the first character position of the next line. If you select None, automatic indentation is disabled for the selected language. The first group of tab settings allow you to change the way that indentation is added automatically when you press Enter within a code editor. Other languages and Visual Studio versions will appear similar. The image below shows the settings for the C# programming language in Visual Studio 2005. Expand the Text Editor section in the tree and then the language for which you wish to change settings. To access the tab settings, open the Options dialog box by selecting Options from the Tools menu. You can use different settings for each of the supported languages.
Visual Studio helps to address these problems by allowing you to configure the manner in which text is indented.
You may elect to use only spaces to remove this problem but this can unnecessarily increase the file size, especially with languages that use lots of indentation, such as XML. However, as the width of a tab can vary according to the user's preferences, indentation may appear differently when code is viewed by two developers. In other languages tabs and spaces can be used freely to align code for readability. In some languages white space is significant and can change the meaning of the code if used incorrectly. The type of indentation used for a language can have varied effects.
Indentation in Visual Studio is controlled with the use of the tab key, which can be used to insert tab characters or spaces into the code or to indent or unindent selected lines.
Sensible use of indentation in source code can greatly improve the readability of the code. This article describes the available options and their usage. Visual Studio provides several configuration options that control the insertion of tab and space characters. Indentation is essential to ensure that source code is easy to read.