• RSS Feed

Introduction to VA Snippets

Insert commonly used fragments of code in your source with VA Snippets. In addition to inserting code, VA Snippets can surround selections of code, prompt for user input, insert environment variables, and insert symbols from the context. You can create VA Snippets from scratch, modify defaults, or begin with selections of existing code.

VA Snippets Versus Built-in Snippets

VA Snippets differ from the like-named feature of newer Microsoft IDEs in several ways:

  • VA Snippets are available in all Microsoft IDEs, from Visual C++ 6.0 to Visual Studio 2013
  • VA Snippets can be modified easily, with a built-in editor specifically for VA Snippets. (XML is not required)
  • VA Snippets can be used immediately after modification
  • VA Snippets have greater functionality, and functionality is consistent across all IDEs
  • VA Snippets can be created and modified from their points of use. No external editor or file management is required
  • A user's set of VA Snippets is shared by all IDEs, providing a consistent experience that is easy to manage

Additionally, several VA Snippets define the behavior of features in Visual Assist, such as the format of code created from usage.

Visual Assist installs with numerous default VA snippets, all of which can be modified.

Types of VA Snippets

There are several types of VA Snippets, with the type determining where the VA Snippets appears in the user interface of Visual Assist. For example, VA Snippets with shortcuts are expanded when typing, whereas VA Snippets with only titles must be selected from a menu. In many instances, a single VA Snippet can be associated with multiple types.

Type: With Shortcut

VA Snippets with shortcuts appear in suggestion lists when typing, and expand when selected. If a VA Snippet with a shortcut has a title, the title appears in the suggestion list in lieu of code.

Code appears in suggestion list when shortcut "bas" is typed

Placeholders in the VA Snippet are expanded when accepted

Type: Surround With

VA Snippets that include the placeholder $selected$ are used with the Surround With feature of Visual Assist. These VA Snippets are typically invoked from menus, and surround selections with code fragments.

Example selection of code

VA Snippets of type Surround With are selected from a menu

Selection is surrounded by the VA Snippet, which also specifies the end location of the caret

Type: With Title Only

VA Snippets created with a title only, i.e. without a shortcut and without $selected$, can be invoked only from a menu. These VA Snippets typically hold large or infrequently used blocks of code.

Defaults VA Snippets with title only include ones to insert Doxygen comments

Placeholders are expanded in a Doxygen comment

VA Snippets with shortcuts can have titles as well, but such VA Snippets are not considered of type With Title Only. When a VA Snippet with a shortcut includes a title, the title appears in a suggestion list, in lieu of code, when the shortcut is typed.

Type: Smart Suggestions

When you define a variable in new code you write, Visual Assist can suggest an initial value for the variable. The suggested values vary by type of variable, and are enumerated in VA Snippets of that support Smart Suggestions.

Suggested initial values for an HRESULT are enumerated in a default VA Snippet

Visual Studio 2008 and older

VA Snippets that support Smart Suggestions contain "SuggestionForType" in their titles.

Type: Refactoring

Most of the refactoring and code-generation commands of Visual Assist create or modify code. The VA Snippets of type Refactoring, all of which can be modified, define the format of such code.

VA Snippets define the format of code created by refactoring commands such as Extract Method

VA Snippets of type Refactoring comprise those related to the refactoring and code-generation features of Visual Assist, because any one such VA Snippet might serve several features. For example, the VA Snippet titled Create Implementation is used by Extract Method, as well as Create Implementation.

Type: Required

Several VA Snippets are required by features of Visual Assist, and define the format of code inserted or modified by the features. These VA Snippets are automatically recreated if deleted.

One required VA Snippet defines the format of code surrounded by #ifdef from the VA Outline


VA Snippets can include several types of placeholders expanded when a VA Snippet is invoked.

Placeholder: Reserved String

A reserved string is a placeholder expanded from an IDE setting, project property, system setting, or surrounding code. Many reserved strings are context sensitive. Reserved strings are case sensitive and must be enclosed in dollar signs. Examples include $clipboard$, $DATE$, and $ClassName$.

Placeholder: Environment

An environment placeholder is expanded from the OS environment of the running IDE. Environment placeholders are enclosed in percent signs. Examples include %USERNAME% and %USERDOMAIN%. Environment placeholders are expanded before other types of placeholders, so they may be used as default values for input placeholders.

Placeholder: Input

An input placeholder causes a VA Snippet to prompt for a value. Any string enclosed in dollar signs, as long as the string is not a reserved string, is an input placeholder. Input placeholders can have default values, and all occurrences of a single input placeholder in a VA Snippet are expanded with a single value obtained from the user.

Example Invocation via Menu and Shortcut

The following steps demonstrate the invocation of a VA Snippet to insert a for loop via menu access, followed by steps to invoke the same VA Snippet by shortcut:

  1. Open a C/C++ or C# file
  2. Move the caret to a position suitable for a loop

  3. From the menubar, select VAssistX | Insert VA Snippet...

  4. From the "VA Snippets with shortcuts" submenu, select "for loop forward"

  5. Because the VA Snippet contains placeholders for user prompts, a dialog opens. Enter values for the index and length of the loop.

  6. Select OK to complete expansion of the VA Snippet


Invoke the same VA Snippet via shortcut with the following steps:

  1. In the options dialog for Visual Assist, confirm that VA Snippets are included in suggestion listboxes

  2. Move the caret to a position suitable for a loop

  3. Type "forr" and, if necessary, move the selection to "for loop forward", which is the title associated with the VA Snippet. (If you have an IDE with built-in code snippets, your listbox may include the Microsoft equivalent: forr.)

  4. Select "for loop forward" to open the dialog for user prompts, and select OK to complete expansion of the VA Snippet