使用 Visual Assist X 自动添加注释及常用代码

转自:http://www.wholetomato.com/products/features/vasnippets.asp

VA Snippets

Accelerate the entry of commonly used symbols and code templates with VA Snippets. This feature inserts user-defined static or dynamic text in response to typing a shortcut or selecting a toolbar button or menu item.

With Visual Assist X, VA Snippets entries appear in suggestion listboxes when you type their shortcuts or when you run the Insert VA Snippets command, e.g. from the toolbar. Right-clicking on selected text in the editor allows you to invoke Surround With snippets. Additional snippet options are available on the context menu when you Shift+Right+Click in a source window in pre-2010 versions of Visual Studio.

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. Examples are included with the product and can be easily copied or modified. VA Snippets that expand W to WORD and DW to DWORD are simple examples included in the default C/C++ entries. You modify or create other entries to suit your coding style.

VaSnippetsW.png

Expanded values may contain reserved strings which insert the date, filename, environment variable, etc. You can prompt for user input and place the text caret in the desired position after an expansion.

VaSnippetsDateUserFull.png

Press Tab or Enter to accept a VA Snippets suggestion.

VaSnippetsSpecialExpanded.gif

VA Snippets may be used with C/C++, C#, Visual Basic, HTML/ASP/ASP.NET, XML, JavaScript, VBScript, XAML, and plain text. Separate VA Snippets entries are maintained for each language.

VA Snippets in Suggestion Lists
Shortcuts for VA Snippets are given precedence over other items in a suggestion list. This makes expansion of VA Snippets consistent and dependable. If you have a VA Snippets entry to expand fl to float, typing fl and Tab inserts float under all circumstances. You can type and accept VA Snippets without glancing at suggestion lists.

Case-Sensitive
Shortcuts for VA Snippets are case-sensitive. Typing lowercase w does not expand if you have a VA Snippets entry for W only. You should have a separate entry for w if you want to expand the lowercase letter as well.
Shortcuts for Frequent Use
Shortcuts are assigned typically to VA Snippets that are typed often. VA Snippets for code templates not typed often, e.g. for long code blocks, should be created without shortcuts. Access the former via the shortcut while typing; access the latter 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.

VaSnippetsMenuPrimary
Surround With
VA Snippets containing the reserved string $selected$ are listed on the Surround With (VA X) context menu in the editor and in the menu that is presented when the Insert VA Snippet toolbar button is pressed. This behavior occurs only when text is selected in the editor. Choosing one of these snippets will surround the selected text with the appropriate text from the snippet. Surround With cannot be invoked from a keyboard shortcut, since typing would replace the selected text. However, it is permissible to have a shortcut for these snippets (or otherwise invoke them without a selection present), in which case $selected$ will simply be blank. This allows you to define a single entry to be used with and without a selection.

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.)

VaSnippetsIfMultiple
Editing VA Snippets
Edit VA Snippets with the user interface provided in Visual Assist X. You can edit via one of these methods:
  • VAssistX|Tools menu
  • Advanced|Suggestions node of the Visual Assist X options dialog
  • Tooltip of a suggested VA Snippet (click the tooltip to edit)
  • The context menu when you Shift+Right+Click in a source window in Visual Studio 2008 or earlier

Visual Assist X provides a complete user interface to edit and organize VA Snippets.

VaSnippetsEditor

Use the toolbar buttons or 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 template files within %APPDATA%\VisualAssist\Autotext. 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.

LanguageApplies toTemplate File
C/C++.h .hh .hpp .hxx .ipp .tlh .inl .p .rh .dh .ih .ph .c .cpp .cc .cxx .tli .idl .odlcpp.tpl
C#.cs .csxcs.tpl
Visual Basic.vb .bas .cls .frm .dob .dsmvb.tpl
HTML/ASP/ASP.NET.htm .html .shtml .hta .asp .aspx .asa .asax .ascx .ashx .asmx .masterhtml.tpl
XML.xmlxml.tpl
JavaScript.js .html .asp .aspx1js.tpl
VBScript.vbs .svb .html .asp .aspx1vbs.tpl
XAML.xamlxaml.tpl
Text.txt and extensionless files2txt.tpl
1VA Snippets for JavaScript and VBScript are suggested inside HTML script blocks or server-side scripts of the same type.
2VA Snippets for plain text files may be inserted via the toolbar or context menu, but are not suggested as you type.
Title
Titles identify VA Snippets in suggestion lists and menus. Titles you specify must be unique; if not, only one of the common entries is accessible via shortcut or menu.

If not specified, the title for a VA Snippet defaults to 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 when creating a snippet 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.





Titles may not contain colons.
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 snippet, a suggestion list appears with the expanded code or title. Press Tab or Enter to accept.

Shortcuts may not contain colons.
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 StringMeaning
Date$DATE$Year/month/day formatted as %04d/%02d/%02d
 $DATE_LOCALE$Current date in locale format
 $DAY$Day of month formatted as %d
 $DAY_02$Day of month formatted as %02d
 $DAYNAME$Day abbreviation in locale format
 $DAYLONGNAME$Full name of day in locale format
 $MONTH$Month formatted as %d
 $MONTH_02$Month formatted as %02d
 $MONTHNAME$Month abbreviation in locale format
 $MONTHLONGNAME$Full name of month in locale format
 $YEAR$Year formatted as %d
 $YEAR_02$Year formatted as %02d
Time$HOUR$Hour formatted as %d
 $HOUR_02$Hour formatted as %02d
 $MINUTE$Minute formatted as %02d
 $SECOND$Second 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**
 $$Literal '$' character
Symbol Context$MethodName$Name of containing method
 $MethodArgs$Method parameters
 $ClassName$Name of containing class
 $BaseClassName$Name of base class of containing class
 $NamespaceName$Fully qualified namespace name
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
 $GUID_SYMBOL$Generated GUID formatted with underscores
 $GUID_STRING_UPPER$Uppercase version of $GUID_STRING$
 $GUID_STRUCT_UPPER$Uppercase version of $GUID_STRUCT$
 $GUID_SYMBOL_UPPER$Uppercase version of $GUID_SYMBOL$
 The following reserved strings are available only in refactoring snippets
Refactor$GeneratedPropertyName$Property name generated during Encapsulate Field
 $generatedPropertyName$Same as $GeneratedPropertyName$ but with lower-case first letter
 $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

*Reserved strings beginning with $FILE expand using the case of the current file.
**Omitted from expanded code if there is no selection.
VA Snippets entries containing $GUID_* are available in IDL files.


Access the list of reserved strings using the toolbar button or context menu inside the Code field when editing VA Snippets.

VaSnippetsCodeInsertNew.png
Environment Variables
You can include environment variables in your VA Snippets entries. Visual Assist X expands them as expected. Enclose environment variable names in percent signs when defining the snippet.

Environment variables
Prompting for User Input
Force VA Snippets to prompt for user variables by including non-reserved strings within dollar signs. A prompt dialog appears when the snippet 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.)

VaSnippetsPromptCode.png

To specify default values for user input, use an equals sign immediately after the user variable name, followed by the default value, then the closing dollar sign. Do not add spaces or quotes. If the variable appears more than once in the snippet, provide the default value in the rightmost invocation of the variable.



The defaults will be filled in when the prompt dialog is displayed, and may be overridden by the user.





Suffixes _Lower or _Upper may be appended to user variables within snippets to generate lowercase or uppercase variants. Similarly, suffixes _Camel and _Pascal force only the first character of the replaced user variable to be lowercase or uppercase, respectively. Examples:

Snippet:  $foo$* $foo_Lower$_ptr = new $foo$();
Input:MyClass
Result:MyClass* myclass_ptr = new MyClass();
 
Snippet:$foo$ $foo_Camel$;
Input:MyClass
Result:MyClass myClass;
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++. When opening the VA Snippet Editor from a context menu in the text editor, the correct language section will be expanded automatically.
VA Snippets for Refactoring and Smart Suggestions
Special VA Snippets are used to control the formatting of refactoring operations such as Encapsulate Field and Extract Method, and for use with Smart Suggestions. These snippets have titles that begin with the word Refactor or SuggestionsForType, and may be edited to suit your formatting preferences, such as line breaks. If you make a mistake editing a refactoring snippet and want to restore the default, delete the snippet and restart Visual Studio. These are the built-in Refactoring snippets:

SnippetLanguagesNotes
Refactor Create FileC#Used with Create File and Move Selection to New File refactorings
Refactor Create Header FileC/C++
Refactor Create Source FileC/C++
Refactor Create From Usage Method BodyC++,C# 
Refactor Create From Usage Method Body (C)CInvoked for C code
Refactor Create From Usage Method Body (Managed)C++Invoked for managed C++ code
Refactor Create From Usage Method Body (Platform)C++Invoked for WinRT code
Refactor Create ImplementationC++ 
Refactor Document MethodC/C++,C#,VB 
Refactor Encapsulate FieldC++,C#, VB 
Refactor Extract MethodC/C++,C# 
Snippets used with Smart Suggestions  
SuggestionsForType BOOLC/C++Simple true/false primitives
SuggestionsForType boolC/C++, C#
SuggestionsForType BooleanC#,VB
SuggestionsForType VARIANT_BOOLC++
SuggestionsForType HANDLEC/C++Common handle values
SuggestionsForType HRESULTC++Common COM return values
SuggestionsForType classC++,C#,VBKeywords used in class declarations
SuggestionsForType loopC/C++,C#Keywords used in control structures
SuggestionsForType switchC/C++,C#
Create VA Snippet from Selection
Capture common code constructs from the editor and save as a VA Snippet in one convenient step by selecting the desired code and choosing Create VA Snippet from the VAssistX|Tools menu or the Insert VA Snippet toolbar button.

VA Snippet from Selection

The VA Snippet Editor will appear, showing the selected text in the code window and the first 3 characters of the code as the shortcut. Make any changes you wish to the title, shortcut, or code and press OK or Apply to save.

VA Snippet from Selection
Miscellaneous
All instances of $GUID_* reserved words referenced in the same VA Snippet will use a single generated GUID.
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值