VA Snippets that contain the reserved string $selected$ are used by the Surround With features of Visual Assist. When these VA Snippets expand, $selected$ is replaced with the current selection. If there is no selection, $selected$ expands to an empty string.
Selections may or may not be be on whole-line boundaries. The appropriate selection depends on the expectation of the VA Snippet. For example, a VA Snippet that surrounds a selection with #ifdef and #endif expects whole lines, whereas one that surrounds with ASSERT() does not.
You can surround selected code by invoking a VA Snippet from a menu or by typing a surrounding character. All VA Snippets are available via menu whereas typically only a few are available via surrounding character.
Access via Menu
You can reach the menu of VA Snippets that contain $selected$ via VAssistX in the menubar (Alt+X, W).
You can reach the same menu via the context menu (Right-Click or Shift+F10) of the text editor. The "(VA)" in the menu differentiates Visual Assist from the built-in version of code snippets.
After selecting a block of code and opening the menu of VA Snippets, expand the VA Snippet using an accelerator, Click, Enter, or Tab.
Example
The following VA Snippet is available to surround content of a C/C++ header file.
Access via Surrounding Character
You can expand a VA Snippet with $selected$ by typing a surrounding character. With such a character and a sufficient selection, the VA Snippet is expanded without overwriting a selection in the text editor. Instead, the selection is replaced by the expanded VA Snippet and the typed character is discarded.
In the following example, VA Snippets surround a selection when 'n' is typed.
Surrounding characters should be used sparingly because they can prevent overwriting of selections.
Expanding of VA Snippets via surrounding characters requires another related feature, Surround Selection, to be enabled. The related feature intelligently surrounds selections upon typing of special single characters, some of which operate as toggles, e.g. to comment and uncomment blocks. You can enable surrounding for these special characters and for the characters you associated with VA Snippets in the options dialog for Visual Assist.
By default, VA Snippets with surrounding characters expand whether or not the current selection contains white space. Hence, you must be careful to avoid inadvertent overwriting of small selections such as symbol names. A VA Snippet to surround with Assert() via 'A' will expand when the current selection is "mySymbol", "x < 0", or "x<0".
If multiple VA Snippets have the same surrounding character, a menu opens.
Select an entry or press ESC to clear the menu and insert the surrounding character.
A VA Snippet with a surrounding character but no title or shortcut can be expanded only via its surrounding character.
Visual Studio 2008 and older
In the VA Snippet editor, surrounding characters are denoted by a special syntax in the shortcut field. If the field already contains a normal snippet shortcut, append a space, "SurroundWith=", and the surrounding character. If the field is empty, simply enter "SurroundWith=" and the surrounding character.
Title
VA Snippets with $selected$ may or may not include titles. If a title exists, the title appears in the menu of VA Snippets. If a title does not exist, the first part of the code to be expanded appears. Typically, VA Snippets with $selected$ have titles.
Accelerator
An ampersand in a title identifies an accelerator for efficient selection by keyboard users.
The accelerator appears in menu of VA Snippets.
End a title with &N to make N the accelerator.
Dual Use of Shortcut and $selected$
A VA Snippet that has a shortcut can also include $selected$. If you invoke such a VA Snippet via its shortcut, $selected$ is expanded to an empty string; if you invoke with a selection, the selection is surrounded. This dual use to a VA Snippet--with and without a selection--lets you manage a single VA Snippet that has two, related purposes.
For example, a VA Snippet with shortcut "if" might surround lines of existing code when invoked from a menu, but might insert an empty if() statement when invoked via shortcut.
VA Outline
Two of the Surround-With features of the VA Outline use VA Snippets to surround an item with #ifdef or a namespace.
Surround with Clipboard
If you prefer complete keyboard access without menus or accelerators, you can use the reserved string $clipboard$ in lieu of $selected$ in your VA Snippets. With $clipboard$, you "surround" selections by cutting them, typing a shortcut for a VA Snippet that includes $clipboard$, and letting Visual Assist expand the VA Snippet to include your cut code.
In the following example, VA Snippet "surrounds" a selection cut to the clipboard with an if().
Or in the following example, VA Snippet "surrounds" the clipboard with SizeOf().
Registry Settings