There are开发者_如何学编程 some things that I do a lot in a new project, for example, entering in a simple call to the Google AJAX API to include jQuery. Can I somehow map my own shortcut combo in VS to have it insert this is when I enter my shortcut?
1) You would have to create a Macro that inserts the current text where the cursor is. For example, to insert a timestamp for the highlighted text (like for Migratordotnet) I have this macro in the MyMacros project:
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Imports System.Security.Principal
Public Module Tools
Public Sub DateTimeStamp()
Dim textSelection As EnvDTE.TextSelection
textSelection = DTE.ActiveDocument.Selection
textSelection.Insert(String.Format("{0:yyyyMMddHHmmss}", DateTime.Now))
End Sub
End Module
2) Go to Tools -> Options -> Environment/Keyboard -> Highlight your Macro in the "Show commands containing:" selection -> in the "Press shortcut keys" box do the key combination/chord you want to associate to the macro. As for the "Use new shorcut in:" section, the Global option will apply to every document type in Visual Studio, no matter where the focus is. So for my example above, the command is found at Macros.MyMacros.Tools.DateTimeStamp
.
精彩评论