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.
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.
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.
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.
VA Snippets can include several types of placeholders expanded when a VA Snippet is invoked.
Placeholder: Reserved String
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.
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:
Open a C/C++ or C# file
Move the caret to a position suitable for a loop
From the menubar, select VAssistX | Insert VA Snippet...
From the "VA Snippets with shortcuts" submenu, select "for loop forward"
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.
Press Enter to complete expansion of the VA Snippet
Invoke the same VA Snippet via shortcut with the following steps:
In the options dialog for Visual Assist, confirm that VA Snippets are included in suggestion listboxes
Move the caret to a position suitable for a loop
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.)
Select "for loop forward" to see the in-line prompt and complete expansion of the VA Snippet.
|PartialSnippetShortcutMatches||Suggest VA Snippets on prefixes of shortcuts|
|SharedSnippetsDir||Share VA Snippets|