views:

113

answers:

1

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?

A: 

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.

Agent_9191
What scheme do I apply it to and what section? I chose `(Default)` and `Global` and it didn't work. I saved my Macro as jQuery in MyMacros. I mapped the key command and saved and closed and it doesn't work.
Mark Ursino
I added some additional information and example of how I've used it. Does that help clarify the steps?
Agent_9191
With the code it seemed to work. When I did a macro recording it did -- not sure why. Thanks!
Mark Ursino