Skip to content

Instantly share code, notes, and snippets.

@alexdresko
Created March 5, 2012 21:36
Show Gist options
  • Save alexdresko/1981263 to your computer and use it in GitHub Desktop.
Save alexdresko/1981263 to your computer and use it in GitHub Desktop.
GetSublimeTextKeyBindingsFromVisualStudioKeyboardShortcuts
Sub GetSublimeTextKeyBindings()
Dim cmd As Command
Dim ow As OutputWindow = DTE.Windows.Item(Constants.vsWindowKindOutput).Object
Dim owp As OutputWindowPane
Dim exists As Boolean
Dim i As Integer
Dim sArray() As String
Dim dict As New System.Collections.Generic.Dictionary(Of String, String)()
dict.Add("Edit.NextBookmark", "next_bookmark")
dict.Add("Edit.ToggleBookmark", "toggle_bookmark")
dict.Add("Edit.CommentSelection", "toggle_comment")
dict.Add("Edit.UncommentSelection", "toggle_comment")
sArray = New String() {}
i = 1
exists = False
For Each owp In ow.OutputWindowPanes
If owp.Name = "SublimeTextKeyBindings" Then
exists = True
Exit For
End If
i = i + 1
Next
If exists Then
owp = ow.OutputWindowPanes.Item(i)
Else
owp = ow.OutputWindowPanes.Add("SublimeTextKeyBindings")
End If
owp.Clear()
' Output 1 line per command
For Each cmd In DTE.Commands
Dim binding As Object
Dim shortcut As String
shortcut = ""
For Each binding In cmd.Bindings
Dim b As String
b = binding
If b.Contains("Text Editor::") Or b.Contains("Global::") Then
If shortcut = "" Or b.Contains("Text Editor::") Then
shortcut = b
End If
End If
Next
shortcut = shortcut.Trim().Replace("Text Editor::", "").Replace("Global::", "")
If Not cmd.Name.Trim().Equals("") And Not shortcut.Equals("") Then
Dim split As String() = shortcut.Replace(" ", "").ToLower().Split(",")
Dim result As String = """" + String.Join(""", """, split) + """"
If dict.ContainsKey(cmd.Name) Then
sArray.Resize(sArray, sArray.Length + 1)
sArray(sArray.Length - 1) = vbTab + "{ ""keys"": [" + result + "], ""command"": """ + dict(cmd.Name) + """ }"
End If
End If
Next
Array.Sort(sArray)
owp.OutputString(String.Join(", " + vbCrLf, sArray))
End Sub
@alexdresko
Copy link
Author

By running this macro in Visual Studio 2010, you'll get a list of Sublime Text 2 keyboard bindings that you can copy/paste into your user-specific key binding file in Sublime Text. A couple of things: It's not super pretty (I just hacked it together really quickly) and, to date, it only supports Visual Studio's Edit.NextBookmark and Edit.ToggleBookmark commands. Someone with a lot of time needs to go through and flush out the "dict" collection to map all of Visual Studio's commands to the corresponding commands in Sublime Text. Seems to work very well for me, but I put it here on Gist in case anyone wants to help complete the project.

@Ligren
Copy link

Ligren commented Jun 20, 2019

Hi, thanks for sharing. Does it work for VS 2017? How can I run it?

@alexdresko
Copy link
Author

Wow... I..uhh.. I don't know and I don't remember. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment