Surround Selection

Simple but valuable commands make it easy to surround selections with comment characters, parentheses, braces, and #ifdef for C/C++ users. Commenting style is sensitive to the language.

surroundOption.gif

For example in C/C++, make a selection and type / to begin each line of the selection with //. Type * to surround the selection with /* and */. Type the characters again to eliminate the comment characters.

Start with this selection:

surroundSelection.gif

Type / and get a commented version:

surroundSelectionCommented.gif

Or type * and get this version:

surroundSelectionCom#2C00F3.gif

Similar behavior occurs for the ( and { characters. When editing C/C++, the # character surrounds a selection with #ifdef and #endif.

Commenting Smaller Selections

Select one or more symbols on a line and press / to comment the small selection. Instead of // at the front of a line, your small selection is surrounded by /* and */. Identical behavior occurs when you press *.

surroundSymbol.gif

Commenting Comments

Pressing / when one or more lines are selected comments when columns one and two of the first line do not contain //. Uncommenting occurs only when // appears at the beginning of the first line. This rule exists to accommodate commenting and uncommenting of blocks of code containing comments.

surroundExistingComment.gif

Parentheses

Press ( to surround a selection with parentheses. Press ( again to add another pair. Press Undo to revert the operation.

surroundParentheses.gif

Braces

Press { to surround a selection with braces and indent the selection. The command works best on single or multiple line selections, not on small selections. The Format Selection command of the IDE is run automatically on the new selection. Press Undo to revert the formatting; press Undo a second time to eliminate the braces.

surroundBraces.gif

Running the command when inside a comment or string surrounds only the selection. A compound statement is not created.

surroundString.gif

#ifdef and #endif

For C/C++, press # to surround a selection with #ifdef and #endif. Select one or more lines before pressing #.

surroundIfdef.gif

Specify the value for the #ifdef in the Visual Assist X options dialog. Surrounding is enabled in one place in the options dialog; the value for #ifdef is specified elsewhere since it relates only to C/C++. Though the option is grayed, the edit field still allows entry of the #ifdef value.

surroundIfdefOption.gif