Surround Selection

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

surroundOption.png

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.png

Type / and get a line-commented version:

surroundSelectionCommented.png

Or type * to get a block-commented version:

surroundSelectionCommentedStar.png

The text selection remains so you can uncomment, select more lines, and comment again quickly if necessary.

Similar behavior occurs for the ( and { characters, while the # character behaves differently for each language:

LanguageSurrounding text
C++#ifdef ... #endif
C##region ... #endregion
VB#Region "" ... #End Region

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 *.

surroundSmallSelection.png

Commenting Existing 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.png

Parentheses

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

surroundParentheses.png

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.png

#ifdef and #endif

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

surroundIfdef.png

Specify the default value for the #ifdef in the VA Snippets Editor.

surroundSnippet.png

Regions

For C#, press # to surround a selection with #region and #endregion. VB code is surrounded with #Region "" and #End Region. Select one or more lines before pressing #.

Surround VB region

After the surround operation has been performed, the text caret is automatically placed where the region name should be typed.

Surround VB region

Text formatting and caret placement are specified using the VA Snippets Editor.

surroundSnippetRegion.png