Managing Code Formatting

Microsoft Script Editor

Managing Code Formatting

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

Indenting

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

To choose an indentation style

  1. On the Tools menu, click Options, and then click Text Editor.
  2. Click the HTML folder, or click All Languages to affect indentation settings for all languages.
  3. Click Tabs, click one of the options under Indenting, and then 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 indentation style to use. For example, if you are creating a For…Next loop in VBScript, the lines are indented accordingly.

To change indent tab settings

  1. On the Tools menu, click Options, and then click Text Editor.
  2. Click the HTML folder, or click All Languages to affect indentation settings for all languages, and then click Tabs.
  3. To specify that tab characters are used in tab and indentation operations, click Keep tabs. To specify that space characters are used, click Insert spaces.
  4. If you select Insert spaces, you can enter the number of space characters each tab or indent represents in the Tab size or Indent size box, respectively.

To indent code

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

To unindent code

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

To automatically indent all of your code

  1. Click Options on the Tools menu, and then click Text Editor.
  2. Click All Languages and then click Tabs.
  3. Under Indenting click Smart.

Hiding Text

By default, all text is displayed in the Script 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 View only)–Hidden text that is concealed gives no indication that it is missing from view. The only way to tell is to turn on line numbering. HTML View uses concealed text to provide 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 text is not deleted.
  • Collapsed   You can choose to hide selected text from view by creating an outlining section. To do this, select the text, and then click Hide Selection on the Outlining submenu of the Edit menu. The text then collapses under the top-most selected line, and a plus sign (+) is displayed 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.

    Note   A regular find operation searches for text in hidden regions based on the setting of an option in the Find dialog box, but an incremental search does not search for text in hidden regions.

Converting Text to Upper and Lowercase

You can use commands to convert text to all upper or lowercase.

To switch text to upper or lowercase

  1. Select the text you want to convert.
  2. To convert text to uppercase, press CTRL+SHIFT+U, or click Make Uppercase on the Advanced submenu of the Edit menu.
  3. To convert text to lowercase, press CTRL+U, or click Make Lowercase on the Advanced submenu of the Edit menu.

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 it over them.
  • Open the URL site when single-clicked, if the URL is valid.