This documentation is archived and is not being maintained.

Managing Code Formatting

Visual Studio .NET 2003

The Visual Studio Code Editor gives you the ability to format your code with options such as indenting, hiding text, displaying URLs, and so forth. The language engine also provides features to auto-format your code as you type through Smart Indenting.


You can choose three different styles of text indenting. You can also specify how many spaces compose a single indentation or tab, and whether the Editor uses tabs or space characters when indenting.

To choose an indention style

  1. On the Tools menu, click Options.
  2. Click Text Editor.
  3. Select the folder for your language, for example, Basic, or select All Languages to affect indenting settings for all languages.
  4. Click Tabs.
  5. Select one of the options under Indenting and click OK:
    • None The cursor goes to the beginning of the next line.
    • Block The cursor aligns the next line with the previous line.
    • Smart (Default) The language service determines the appropriate indention style to use. For example, if you creating a For...Next loop in Visual Basic, the lines are indented accordingly.

To change indent tab settings

  1. On the Tools menu, click Options.
  2. Click Text Editor.
  3. Select the folder for your language, for example, Basic, or select All Languages to affect indenting settings for all languages.
  4. Click Tabs.
  5. To specify that tab characters are used in tab and indent operations, select Keep Tabs. To specify that space characters are used, select Insert Spaces.

    If you selected Insert Spaces, you can enter the number of space characters each tab or indent represents under Tab Size or Indent Size respectively.

To indent code

  1. Select the text you want to indent.
  2. Click the TAB key, or click Indent .

To unindent code

  1. Select the text you want to unindent.
  2. Press SHIFT+TAB key, or click Unindent .

To automatically indent all of your code

  1. In Tools, Options, select Text Editor, All Languages, Tabs, and then select Smart from the Indenting group box.
  2. To select this option on a per-language basis, select Smart in the appropriate folder, starting by selecting Options from the Tools menu. For example, to set Smart formatting for Visual Basic, select Smart from the Indenting group box in Text Editor, Basic, Tabs.

To automatically indent selected code

  1. Select the text you want to automatically indent.
  2. Click Format Selection in Edit, Advanced, or press CTRL+K, CTRL+F.

    Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.

You can specify size of the tabs and the indents and whether or not the tab characters are converted to spaces. For more information, see Tabs, CSS, Text Editor, Options Dialog Box.

To convert white space to tabs and vice versa

  1. Select the text whose white space (that is, the spaces between the characters) you want to convert from spaces to tabs.
  2. In Edit, Advanced, click Tabify Selection.
  3. To convert tabs to spaces, in Edit, Advanced, click Untabify Selection.

The functionality of these commands depends on the tab settings in Tools, Options, Text Editor, Tabs. For example, if the tab setting is four, Tabify Selection creates a tab for every four contiguous spaces, and Untabify Selection creates four spaces for every tab.

Hiding Text

By default, all text is displayed in the Code Editor, but in some circumstances you can hide the code from view. For details about this, see Outlining and Hiding Code. There are two different types of hidden text:

  • Concealed (HTML Designer HTML view only) – Hidden text that is concealed has no indication that it is missing from the view. The only way to tell is to turn on line numbering. The HTML view of HTML Designer uses concealed text to provide you with a Script-only view where all text that is not part of the script code is hidden from view. If you select across concealed text and delete it, the non-visible concealed text is not deleted.
    Note   In the HTML Designer's HTML view, you can activate a "Script-Only" view in which only script blocks are displayed.
  • Collapsed – You can choose to hide selected text from view by creating an outlining section. To do this, select the text, right-click, and click Hide Selection. The text then collapses under the top-most selected line, and a plus-sign (+) symbol displays in the indicator margin to the left of the line. To expand the lines for viewing, click the plus sign. The same procedure applies to outlining. If you select across collapsed text and delete it, all selected text is deleted, including the collapsed text.

    The Hide Selection command works only with Stream selection and zero-width Box selection modes. The command is disabled for non-zero-width box selections.

    Languages also support collapsing code to definitions. Some languages, in addition to supporting Collapse To Definitions, have a mode where outlining is always on. As you type new definitions, the editor creates collapsible sections around the definition bodies of the new code. You can stop this with the Stop Outlining command. For more information about this and hiding code in general, see Outlining and Hiding Code.

    Note   A regular Find operation searches for text in hidden regions based on an option in the Find dialog box, but an incremental search does not. Find in Files always searches the entire contents of a file regardless of whether portions of the text are collapsed or concealed.

Converting Text to Upper and Lower Case

You can use commands to convert text to all upper or lower case.

To switch text to upper or lower case

  1. Select the text you want to convert.
  2. To convert text to upper case, click CTRL+SHIFT+U, or click Make Uppercase in Edit, Advanced.
  3. To convert text to lower case, click CTRL+U, or click Make Lowercase in Edit, Advanced.

The case conversion commands do not affect the case of intrinsic commands.

Displaying and Linking to URLs

You can create and display active URLs (Uniform Resource Locators) in your code. You can then click the link and be taken to the web page in a browser. By default, the URLs:

  • Appear underlined.
  • Change the mouse pointer to a hand when you move over them.
  • Open the URL site when single-clicked, if the URL is valid.

To display a clickable URL

  1. On the Tools menu, click Options.
  2. Click Text Editor.
  3. To change the option for only one language, click that language and then click General. To change the option for all languages, click All Languages and then click General.
  4. Under Display, select Enable single-click URL navigation.
    Note   If you turn this option off, you can still open a valid internet site by choosing the Open URL command from the Code Editor's context menu.

See Also

Editing Code, HTML, and Text