Create a keyboard shortcut quick query table.
Most developers do not understand this, but Visual Studio provides over 450 keyboard shortcuts by default. However, there is no easy way to find all keyboard shortcuts in Visual Studio. You can write a simple macro to traverse all the default keyboard shortcuts and find their corresponding operations. The code for this macro is listed below (List 1.
Public Module Module1
Public Sub ListShortcutsInHTML()
'Declare a StreamWriter
Dim sw As System.IO.StreamWriter
sw = New System.IO.StreamWriter("c:\\Shortcuts.html", True, System.Text.Encoding.GetEncoding("SHIFT-JIS"))
'Write the beginning HTML
WriteHTMLStart(sw)
' Add a row for each keyboard shortcut
For Each c As EnvDTE.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(" sw.WriteLine(" sw.WriteLine("<title>")
sw.WriteLine("Visual Studio Keyboard Shortcuts")
sw.WriteLine("</title>")
sw.WriteLine("
sw.WriteLine("<body>")
sw.WriteLine(" 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(" End Sub
End Module
List 1. Generate a keyboard shortcut macro in the HTML file
To use this macro, go to "tool", select "macro", and select "macro ide..." to start "macro ide ". Expand the mymacros project, name the mymacros, and double-click module1 ". Copy the content in List 1 to "macro ide" and then run the macro. After running the macro, the keyboard shortcut reference information of Visual Studio is generated. Open the c: \ demo \ shortcuts.html file containing the output content. Figure 1 shows some output content. Print it out and paste it near your computer to learn new keyboard shortcuts.