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.
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/snippetbassuggested.ashx?la=en&hash=CB9A35A833A371E4F233E0CC2174D3DBCFCFFBBB)
Placeholders in the VA Snippet are expanded when it is accepted.
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/snippetbasexpanded.ashx?la=en&hash=95E1EBBDD54557C79D819DA554522D1B06542932)
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.
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/snippetsurroundselected.ashx?la=en&hash=85B66E70C9A9B933368448668BBF0EE3D411A10B)
VA Snippets of type Surround With can be selected from a menu.
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/snippetsurroundmenu.ashx?la=en&hash=68A85D4BF5AEE77872A70D8D2DA04FE5C8D44102)
The location of the caret after expansion is determined by the VA Snippet.
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/snippetsurroundexpanded.ashx?la=en&hash=A51D8B6C052360FB3015D1854A9CBB145BB7EB92)
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.
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/snippettitleonlymenu.ashx?la=en&hash=5AC4F562C647036616AA80F49A06BA21DCB36DE5)
In these VA Snippets, placeholders are expanded to form a Doxygen comment.
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/snippettitleonlyexpanded.ashx?la=en&hash=6368232435CC1D71F1E00433AC5DFE94750A7240)
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.
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/snippetsuggestionfortype.ashx?la=en&hash=C258B3A9F3BDFCFDAA31F60E85EEE7CB6A7597AB)
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.
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/moveimplementation.ashx?la=en&hash=7BD998A1868EC68CD66276CAEE9C87439A19945C)
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.
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/snippetvaoutlinesurround.ashx?la=en&hash=EF3DE453E71BF834E17FBAFFF053B2F7C4360BA0)
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:
- Open a C/C++ or C# file
- Move the caret to a position suitable for a loop
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/examplepositioncaret.ashx?la=en&hash=151260C82C4178BD7DD94191DFF16D908CA79021)
- From the menubar, select VAssistX | Insert VA Snippet...
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/examplevassistx.ashx?la=en&hash=B6AB2F70E7D3217F2048918847AE553631DE62C5)
- From the "VA Snippets with shortcuts" submenu, select "for loop forward"
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/examplemenuforr.ashx?la=en&hash=1B6838336358499A2936AA4C7A7A098D1160A536)
- 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.
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/snippetsintroinline.ashx?la=en&hash=E118572DB5443E276D245EAF655FC8F9D7A9E6AF)
- Press Enter to complete expansion of the VA Snippet
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/exampleexpanded.ashx?la=en&hash=1C2249B0D15BFAC5B6ADA5FB2B3281F7A7E069AF)
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
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/includevasnippets.ashx?la=en&hash=4F7B77FE38CE106D95726BA95031CDA032D4C691)
- Move the caret to a position suitable for a loop
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/examplepositioncaret.ashx?la=en&hash=151260C82C4178BD7DD94191DFF16D908CA79021)
- 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.)
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/example2suggestionlist.ashx?la=en&hash=4DE54BB0FB941BCA3FE963D5DC5C6371A86328C9)
- Select "for loop forward" to see the in-line prompt and complete expansion of the VA Snippet.
![](/~/media/wholetomato/kb/documentation/introduction-to-va-snippets/exampleexpanded.ashx?la=en&hash=1C2249B0D15BFAC5B6ADA5FB2B3281F7A7E069AF)
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