Setting Syntax Coloring

Home Page (Text Editor) | Overview | How Do I ... Topics | FAQ | Reference

Syntax coloring uses different colors for various elements of your code, such as keywords or comments. This coloring gives you visual cues about the structure and state of your code.

What do you want to know more about?

Syntax coloring

What do you want to do?

Set syntax coloring for one source file

Change colors used for syntax coloring

Set syntax coloring for user-defined keywords

Set syntax coloring for extensionless header files

Set syntax coloring for a custom HTML variation

To set syntax coloring for one source file

  1. From the Window menu, select the source window you want to activate.

    If there are multiple windows open on the same source file, select one. Syntax coloring changes will appear in all windows.

  2. From the View menu, choose Properties.

    The Source File Properties page appears. The Language box displays the current language setting for syntax coloring. The drop-down list contains the available language choices.

  3. In the Language box, select the language for which you want to set syntax coloring, or select None to turn syntax coloring off.

  4. Close the property page.

    The choice you made takes effect.

*Tip* If you create or save a file with a recognized extension (such as VBS, CPP, or HTM), syntax coloring for the language indicated by that extension takes effect immediately.

To change colors used for syntax coloring

  1. From the Tools menu, choose Options.

  2. Select the Format tab.

  3. In the Category box, select the type of window for which you want to define formatting.

  4. In the Font box, select the font you want.

    The Font box displays the different fonts installed on your system. The text sample in the sample box changes to the font you select.

  5. In the Size box, select the size to be used with the font you selected.

    The Size box displays the sizes available for the selected font. The text sample in the sample box changes to the size you select.

  6. In the Colors box, select the type of text you want to color.

  7. In the Background box, select a background color.

  8. In the Foreground box, select a foreground color.

    The Background and Foreground boxes display the 16 standard colors and the Automatic setting. The text sample displayed in the Sample box changes to the color you select.

    The behavior of the Automatic setting depends on the element selected. For colors that map to standard system elements (such as Foreground Color, Background Color, or Selected Text Color), the Automatic setting sets the element to the appropriate system color. For syntax coloring elements and other non-system defined colors, the Automatic setting indicates that the foreground color or background color from the same category is to be used.

  9. Click OK.

To set syntax coloring for user-defined keywords

  1. In the same directory as msdev.exe, use the Text editor or Windows Notepad to create a text-only file named usertype.dat.

  2. Add your keywords to usertype.dat, one keyword per line.

    *Note* The usertype.dat file is read during initialization. It cannot be renamed, nor can it be reloaded during an editing session. The syntax coloring mechanism checks the usertype.dat file last. Thus, all previously defined color settings take precedence over the user-defined keywords.

  3. Save the file as a text-only file, exit, and then restart Visual Studio.

  4. From the Tools menu, choose Options.

  5. Select the Format tab.

  6. In the Colors box, select User Defined Keywords.

  7. Set the font, font size, foreground color, and background color to your preferences.

    For more information, see To change colors used in syntax coloring.

  8. Click OK.

*Tip* For any source file, you can use the Source File Properties page to specify which language syntax coloring to apply (or turn off syntax coloring altogether). For more information, see Setting Font Style, Size, and Color.

To set syntax coloring for extensionless header files

  1. Open the langext.dat file. This file resides in the same directory as msdev.exe.

  2. Add the filenames you want to color to the file.

  3. Save the file.

*Note* The langext.dat file pairs filenames with a language. This file is consulted only when extension matching fails. That is, an HTML file is always identified as HTML, not as C/C++, even if it is listed in the C/C++ section of langext.dat.

To set syntax coloring for a custom HTML variation

  1. Create a text file with an extension of .hlx in the \msdev\bin\ide directory.

    The first line of the file is a signature that uniquely identifies the type of the file. It contains the name of the variation that will be displayed on the Source File Properties page. After the signature line, the format resembles that of a Windows initialization file. A semicolon at the beginning of a line indicates a comment.

  2. Create three sections in the file: an [Elements] section, an [Attributes] section, and an [Entities] section.

    Each section contains a list of names separated by spaces, carriage returns, or line feeds. The names do not need to be in alphabetical order. You must specify all the elements, attributes, and entities you want to color.

    See the example for a general outline of a sample .hlx file.

  3. Save the .hlx file.

*Note* If the custom variation you specify in the .hlx file has the same name as a built-in HTML support, it will override the built-in HTML support. There is a 14-character limit to the name of the HTML variation you specify.

Sample .hlx file

The following example gives the general outline of an .hlx file. For brevity, this example is shortened to omit most names.

@HLX@ "HTML - Custom"
; Custom HTML tagset file.
; Must begin with the "@HLX@" signature and
; the name of the HTML variant in quotes. The
; name is limited to 14 characters.
; Element set, case-insensitive
; HTML tags, e.g. <H1>


; break control

; headings
H1 H2 H3 H4 H5 H6

; character formatting

; etc. ...

; Attribute set, case-insensitive
; (applied to all elements)


; etc. ...

; Entity set, case-sensitive
; special characters, e.g. &amp;
; If this section is empty or omitted, the standard set from RFC1866 is used.

gt lt amp quot
; etc. ...