Partilhar via


Visual Studio Macro to Output All Key Bindings

In my new role I’m primarily developing in C# whereas my primary language in the past has been Visual Basic .NET. With a different language, comes a different Visual Studio profile, and with a different Visual Studio profile comes different key bindings.

This Visual Studio macro outputs each Visual Studio command (alphabetically) and its associated key bindings. When run the key bindings will be output to Visual Studio’s Output window, from here you can copy and paste them into whatever format you want.

Public Sub DumpBindings()

    Dim commands As New System.Collections.Generic.Dictionary(Of String, System.Collections.Generic.List(Of String))

    For Each command As Command In DTE.Commands

        Dim bindings As Object() = DirectCast(command.Bindings, Object())

       If String.IsNullOrEmpty(command.Name) OrElse bindings.Length = 0 Then

        Continue For

        End If

        commands.Add(command.Name, New System.Collections.Generic.List(Of String))

        For Each binding As Object In bindings

        Dim bindingValue As String = DirectCast(binding, String)

        commands(command.Name).Add(bindingValue)

        Next

    Next

    Dim commandNames(commands.Keys.Count - 1) As String

    commands.Keys.CopyTo(commandNames, 0)

    Array.Sort(commandNames)

    For Each commandName As String In commandNames

    Debug.WriteLine(commandName)

    commands(commandName).Sort()

    For Each binding As String In commands(commandName)

    Debug.WriteLine("{0}{1}", ControlChars.Tab, binding)

    Next

    Next

End Sub