VA Snippets
Accelerate the entry of commonly used symbols and code snippets with VA Snippets. VA Snippets is similar to the like-named feature of Microsoft Word which expands dates and days of the week. VA Snippets incorporates the separate feature, Code Templates, of older versions of Visual Assist X.
With Visual Assist X, VA Snippets entries appear in suggestion listboxes when you type their shortcuts, in the
context menu when you Shift+Right+Click in a source window, and when you run the InsertVA Snippets command, e.g. from the toolbar.
You create the list of VA Snippets shortcuts and their expanded values, and what titles are to appear in menus when you want to insert large code snippets.
You can also edit VA Snippets through the use of a
shortcut key.
VA Snippets that expands T to TRUE and F to FALSE are simple examples included in the default VA Snippets entries. You modify or create other entries to suit your coding style.
Expanded values may contain special characters which insert the date, filename, environment variable, etc. You can prompt for user input and place the text caret after an expansion.
Press Tab or Enter to accept a VA Snippets suggestion.
VA Snippets is available for all languages, including C/C++, C#, ASP and VB. Separate VA Snippets entries are maintained for each language.
VA Snippets Versus Suggestions and Completions
Shortcuts for VA Snippets have precedence over any other item that might appear in a
suggestion list. This makes expansion of VA Snippets consistent and dependable.
If you have a VA Snippets entry to expand T to TRUE, typing T and Tab inserts TRUE under all circumstances. Typing T does not produce a listbox with any other suggestions. You can type and accept VA Snippets without glancing at suggestion lists.
If you type beyond the shortcut for a VA Snippets entry, if even the next character is part of the expanded string, the suggestion list with the VA Snippets is replaced with a normal suggestion list. The new list may or may not contain your expanded VA Snippets.
If a suggestion list with a VA Snippets entry is visible, press Ctrl+Space to force open a completion listbox. The listbox will contains all symbols valid in the context that begin with your VA Snippets shortcut.
Case Sensitive
Shortcuts for VA Snippets are case sensitive. Typing lower case t does not expand if you have a VA Snippets entry for T only. You should have a separate entry for t if you want to expand the lowercase letter as well. For this reason, the default VA Snippets file for C/C++ has an entry to expand t to true.
Shortcuts for Frequent Use
Shortcuts are assigned typically to VA Snippets that are typed often. VA Snippets for code snippets not typed often, e.g. for long code blocks, should be created without shortcuts. Access to the former form is via the shortcut; access to the latter form is available only from menus -- a UI more suited for infrequent use.
VA Snippets without shortcuts are readily available when a menu of VA Snippets opens. VA Snippets with shortcuts are available in a submenu.
In summary, avoid assigning shortcuts to VA Snippets you expect to select from a menu
Duplicate Entries
You can create multiple VA Snippets entries with the same shortcut. All entries are listed when you type the shortcut. Select the one you want from the suggestion listbox. (If you specify your own titles, make sure they are unique.)
Editing VA Snippets
Edit VA Snippets with the user interface provided in Visual Assist X. You can edit via a button on the
Advanced|Suggestions node of the Visual Assist X
options dialog, via an icon when you hover over suggested VA Snippets, or via "Edit VA Snippets..." in the
context menu when you Shift+Right+Click in a source window.
Visual Assist X provides a complete user interface to let you edit and organize VA Snippets.
Use the context menu in the expansion tree to create, save and delete VA Snippets.
Locating Definitions
If you prefer to use an external text editor, locate VA Snippets in files within C:\Users\
username\AppData\Roaming\VisualAssist in Windows Vista, or C:\Documents and Settings\
username\Application Data\Visual Assist in Win2K or Windows XP. If you choose not to overwrite your own VA Snippets during installation, you may obtain the latest default files from the Visual Assist X installation directory under C:\Program Files\Visual Assist X\AutoText\Latest\*.tpl.
| Language | File |
| C/C++ | cpp.tpl |
| C# | cs.tpl |
| Visual Basic/VBScript | vb.tpl |
| HTML/XML/ASP | html.tpl |
| JavaScript | js.tpl |
| Perl | perl.tpl |
| Text | txt.tpl |
Title
Titles you specify must be unique. If not, only one of the common entries is accessible via shortcut or menu.
The default title for VA Snippets is the code to which it expands. This is the recommended value for most VA Snippets, particularly for entries with shortcuts or small expansions. Leave the title field blank to use the default.
If your expanded code is lengthy or not unique, you can give an entry a title which is displayed instead of the expanded code. If the entry has a shortcut, the title appears when you type the shortcut. If the entry does not have a shortcut, the title appears when you open a menu of VA Snippets.
Shortcut
Specify a shortcut for VA Snippets you expect to use often. When you type the shortcut in a source window for the language associated with the VA Snippets, a suggestion list appears with the expanded code or title. Press Tab to accept.
The only special characters that may appear in the shortcut are ones that begin C/C++ comments, hyphen and #. If a shortcut begins with comment characters, only hyphen, slash or plus may follow the comment characters.
Description
You can document your VA Snippets entries using the optional description field. The field is not used in any other manner.
Code
Type your expanded code into the Code field. Include reserved strings to expand the date, filename and more.
| Reserved String | Meaning |
| Date | $DATE$ | Year/month/day formatted as %04d/%02d/%02d |
| $DAY$ | Day of month formatted as %d |
| $DAY_02$ | Day of month formatted as %02d |
| $DAYNAME$ | Three-character abbreviation of day |
| $DAYLONGNAME$ | Full name of day |
| $MONTH$ | Month formatted as %d |
| $MONTH_02$ | Month formatted as %02d |
| $MONTHNAME$ | Three-character abbreviation of month |
| $MONTHLONGNAME$ | Full name of month |
| $YEAR$ | Year formatted as %d |
| $YEAR_02$ | Year formatted as %02d |
| File | $FILE$ | Full filename with path* |
| $FILE_UPPER$ | Full filename with path in uppercase* |
| $FILE_BASE$ | Filename without path or extension* |
| $FILE_BASE_UPPER$ | Filename without path or extension in upper case* |
| $FILE_EXT$ | Filename extension* |
| $FILE_EXT_UPPER$ | Filename extension in upper case* |
| $FILE_PATH$ | Path of file* |
| $FILE_PATH_UPPER$ | Path of file in upper case* |
| General | $clipboard$ | Current clipboard |
| $end$ | Position of caret after expansion |
| $selected$ | Current selection** |
| $$ | $ |
| GUID | $GUID_DEFINITION$ | Generated GUID formatted for use in a definition |
| $GUID_STRING$ | Generated GUID formatted for use in a string |
| $GUID_STRUCT$ | Generated GUID formatted for use in a struct |
| (Note that all instances of GUID reserved words will use a singe generated GUID.)
|
| Refactor | $GeneratedPropertyName$ | Property name generated during Encapsulate Field |
| $MethodArg$ | One parameter of the method and its type |
| $MethodArgName$ | One parameter of the method |
| $MethodArgType$ | Type of one parameter of the method |
| $MethodBody$ | Body of implementation |
| $MethodQualifier$ | Optional qualifiers of method |
| $ParameterList$ | Parameters separated by commas |
| $SymbolContext$ | Context and name of method |
| $SymbolName$ | Name of method |
| $SymbolPrivileges$ | Access of method |
| $SymbolStatic$ | Keyword static or blank |
| $SymbolType$ | Return type of method |
| $SymbolVirtual$ | Keyword virtual or blank |
| Time | $HOUR$ | Hour formatted as %d |
| $HOUR_02$ | Hour formatted as %02d |
| $MINUTE$ | Minute formatted as %02d |
| $SECOND$ | Second formatted as %02d |
*Reserved strings beginning with $FILE expand using the case of the current file.
**Lines with whitespace and $selected$ are omitted from expanded code if there is no selection. (This lets you define a single entry to be used with and without a selection.)
VA Snippets entries containing $GUID_* are available in IDL files.
Access the list of reserved strings using the context menu inside the Code field when editing VA Snippets.
Environment Variables
You can include environment variables in your VA Snippets entries. Visual Assist X expands them as expected.
Define environment variables with the features of your operating system.
Prompting for User Input
Force VA Snippets to prompt for input by including non-reserved strings within dollar signs. A prompt dialog appears when the VA Snippets is expanded via a shortcut or selection from a menu. The non-reserved string is the prompt. You can prompt for a maximum of eight values.
In the following example, VA Snippets will prompt for Index and Length. (The expanded code is available on a separate tab when the prompt dialog appears.)
Separate VA Snippets for Separate Languages
Visual Assist X maintains separate VA Snippets entries for each language it supports. You must copy or retype entries you want to apply to multiple languages.
Make sure you edit VA Snippets for the language you expect. It is a common mistake to edit VA Snippets for C# when you intend to edit entries for C/C++.
Special Note About HTML/XML/ASP
VA Snippets for HTML, XML and ASP files is available only inside script blocks. The IDE might offer assistance in other code.