Table of content
WholeTomato

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.

Visual Assist versus Visual Studio

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

  • VA Snippets are available in all Microsoft IDEs, not just newer ones.
  • 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 versions of the IDE.
  • 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 type determining where the VA Snippets appear 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.

In the following example, code appears in the suggestion list when shortcut "bas" is typed.

Placeholders in the VA Snippet are expanded when it is accepted.

Type: Surround With

VA Snippets that include the placeholder $selected$ are used with the Surround With feature of Visual Assist. These VA Snippets, invoked via menus or single characters, surround selections with code fragments. The VA Snippets can be invoked without or with a selection.

VA Snippets of type Surround With can be selected from a menu.

The location of the caret after expansion is determined by the VA Snippet.

Type: With Title Only

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

You can add a & to the title inside the VA Snippet editor, to mark the next character as the shortcut letter in the VA Snippet menu, for quick and easy access.

Default VA Snippets with-title-only include ones that insert Doxygen comments.

In these VA Snippets, placeholders are expanded to form 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, 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 type Smart Suggestions.

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 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 Create Implementation as well as Move Implementation to Source File.

Type: Required

Several VA Snippets are required by features of Visual Assist; they define the format of code inserted or modified by the features, e.g. #ifdef. These VA Snippets are automatically recreated if deleted.

Placeholders

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, an in-line prompt appears in the text editor. Enter values for the index and length, using tab to move between placeholders.


     
  6. Press Enter 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 see the in-line prompt and complete expansion of the VA Snippet.

Private versus Shared VA Snippets

Visual Assist supports private VA Snippets, which are shared among all IDEs for a single developer, and shared VA Snippets, which are stored in a public location and shared among multiple users of Visual Assist. By default, Visual Assist installs and uses only private VA Snippets. Adjust the registry to share VA Snippets among users.

Backup and Restore

VA Snippets of type "Required" are automatically recreated to default state if deleted. No other type of snippet is recreated or restored if deleted.

Undoing of edits to VA Snippets is limited to a single session of the snippet editor.

If you want the option of restoring a VA Snippet to a pre-edited state, copy and paste the snippet before making extensive edits to it.

VA Snippets may be backed up, en masse, using software external to Visual Assist and the IDE. VA Snippets are stored in .tpl files in:

%APPDATA%\VisualAssist\Autotext

On the extremely rare occasion that Visual Assist must overwrite .tpl files during installation, .tpl files containing custom snippets will be moved to:

%APPDATA%\VisualAssist\Autotext\Saved

Registry Settings

Value Name Meaning
PartialSnippetShortcutMatches Suggest VA Snippets on prefixes of shortcuts
SharedSnippetsDir Share VA Snippets among users