• RSS Feed

Introduction to VA Snippets

VA Snippets are reusable code templates that let you insert commonly used code fragments in your code, and surround selected portions with additional code. VA Snippets may contain placeholders that are expanded—from the environment, surrounding code, or user input—when a VA Snippet is applied.

One set of VA Snippets is used by all IDEs in which Visual Assist is active, providing a consistent experience that is easy to manage. 

VA Snippets differ from the like-named feature of newer Microsoft IDEs in that VA Snippets can be modified easily (no XML), and used immediately after modification. In addition, VA Snippets are used to change behavior of several other features in Visual Assist, including the format of refactored code and code created from usage.  Visual Assist installs with numerous default VA snippets, all of which can be modified to accommodate preferences for access and formatting standards.

VA Snippet that demonstrates use of placeholders
Sample VA Snippet expanded in text editor

Types of VA Snippets

There are several types of VA Snippets, and the types serve different but related purposes. The type of a VA Snippet determines where it appears in the user interface of Visual Assist. For example, VA Snippets with shortcuts are expanded when typing, whereas another VA Snippet defines initial values to be suggested when defining a variable. In some instances, a single VA Snippet can be associated with more than one type.

The types of VA Snippets are:

  • With Shortcuts, which appear in suggestion lists when typing and expand when selected. Any VA Snippet with a shortcut can be expanded when typing, and multiple VA Snippets can have the same shortcut. 
    VA Snippet with a shortcut that can be expanded by typing "bas"
  • With $selected$, which are typically selected from menus and wrap a selection with additional code. If one of these VA Snippets is invoked using a shortcut, the $selected$ reserved string expands to the empty string.
    VA Snippet with $selected$ that can be expanded via menu and by typing "do"
  • With $clipboard$, which are invoked via shortcut after copying a block of code to the clipboard. (Users typically use $selected$ or $clipboard$, not both, depending on preference for access.)
    VA Snippet with $clipboard$ typically expanded by typing "do"
  • With Title Only, which are infrequently used blocks of code whose only access method is by menu.
    Infrequently used VA Snippet with title only, invoked only via menu
  • Refactoring, which define the format of refactored code.
    VA Snippet that defines format of encapsulated fields
  • Suggestions for Type, which define initial values suggested when defining variables.
    VA Snippet that defines suggested initial values for an HRESULT
  • Surround Selection, which define the format of code surrounded by #ifdef or #region when typing a single #.
    VA Snippet that defines format of code surrounded when typing #


Placeholders in VA Snippets are expanded to content-sensitive values when a VA Snippet is invoked. The types of placeholders are:

  • Reserved Strings, which are enclosed in $ symbols within a VA Snippet. Examples include $clipboard$, $DATE$, and $ClassName$. Values are extracted from IDE settings, project properties, system settings, and surrounding code. Reserved strings are context sensitive, so $ClassName$ expands whereas $classname$ does not.
  • Environment Variables, which are enclosed in % symbols, e.g., %USERNAME%. Environment variables are expanded before other types of placeholders, so they may be used as default values for user input. Environment variables are case insensitive, so %USERNAME% is equivalent to %UserName%.
  • User Prompts, which are enclosed in $ symbols and are not recognized reserved strings. When a VA Snippet with a user prompt is invoked, a dialog appears to obtain its expanded value. User prompts can have default values, and all occurrences of a user prompt in a VA Snippet are replaced with the expanded value. User prompts are case sensitive, so $USERINPUT$ is considered different from $UserPrompt$.

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