Jun
12th | 2008

Creating Visual Studio Keyboard Shortcuts Cheat Sheet

Filed under .Net, Visual Studio | Posted by Shahar Y

After publishing 10 Visual Studio shortcuts you must know and then 11 more Visual Studio shortcuts, a colleague of mine, Elan Kynsky, introduced me an MSDN page called Visual Studio 2005 IDE Tips and Tricks. This is a long article where you can learn cheatsheeta couple of useful things about Visual Studio, but what attracted me most, was the “Creating a keyboard shortcuts cheat sheet” section.

As we all know, there are a lot of keyboard shortcuts in Visual Studio. We mentioned only 21 of them here at Dev102.com but according to this article, there are about 450 shortcuts available. That fact, made me realize that I know less than 10% of them… Fortunately, we can write a macro that enumerate all of the available shortcuts. To achieve that goal, go to Tools->Macros->”Macros IDE”, a macros window will pop up, expand the MyMacros project (in the project explorer), expand MyMacros namespace and double click on Module1. Copy the following code to the Macros IDE and run it.

The code, copied from the article:

Public Module Module1

    Public Sub ListShortcutsInHTML()

        ‘Declare a StreamWriter
        Dim sw As System.IO.StreamWriter
        sw = New StreamWriter(“c:\\demo\\Shortcuts.html”)

        ‘Write the beginning HTML
        WriteHTMLStart(sw)

        ‘ Add a row for each keyboard shortcut
        For Each c As Command In DTE.Commands
            If c.Name <> “” Then
                Dim bindings As System.Array
                bindings = CType(c.Bindings, System.Array)
                For i As Integer = 0 To bindings.Length - 1
                    sw.WriteLine(“<tr>”)
                    sw.WriteLine(“<td>” + c.Name + “</td>”)
                    sw.WriteLine(“<td>” + bindings(i) + “</td>”)
                    sw.WriteLine(“</tr>”)
                Next

            End If
        Next

        ‘Write the end HTML
        WriteHTMLEnd(sw)

        ‘Flush and close the stream
        sw.Flush()
        sw.Close()
    End Sub
Public Sub WriteHTMLStart(ByVal sw As System.IO.StreamWriter)
        sw.WriteLine(“<html>”)
        sw.WriteLine(“<head>”)
        sw.WriteLine(“<title>”)

        sw.WriteLine(“Visual Studio Keyboard Shortcuts”)
        sw.WriteLine(“</title>”)
        sw.WriteLine(“</head>”)

        sw.WriteLine(“<body>”)
        sw.WriteLine(“<h1>Visual Studio 2005 Keyboard Shortcuts</h1>”)
        sw.WriteLine(“<font size=”“2″” face=”“Verdana”“>”)
        sw.WriteLine(“<table border=”“1″“>”)
        sw.WriteLine(“<tr BGCOLOR=”“#018FFF”“><td
align=”“center”“><b>Command</b></td><td
align=”“center”“><b>Shortcut</b></td></tr>”)

    End Sub

    Public Sub WriteHTMLEnd(ByVal sw As System.IO.StreamWriter)
        sw.WriteLine(“</table>”)
        sw.WriteLine(“</font>”)
        sw.WriteLine(“</body>”)
        sw.WriteLine(“</html>”)
    End Sub

End Module

Notice that this code creates the following file: C:\demo\Shortcuts.html. To make your life easier, I did the whole process and uploaded the results as a Visual Studio Keyboard shortcuts Cheat Sheet page. You can use it (notice that if you customized some of the keyboard shortcuts, you will have to do the whole process by yourself) and as written in the MSDN article, feel free to print it out and post it near your computer. Hope you find it helpful, enjoy…

Tags: , , , , ,

One Response to “Creating Visual Studio Keyboard Shortcuts Cheat Sheet”



  1. By Glenn on Jun 12, 2008 | Reply

    Is there a Key-Board Shortcut to stop Visual Studio from freezing up and being a CPU pig?

Post a Comment

Search Dev102