Visual Studio Keymaps using F#
I always try and avoid using mouse, for example even for browsing internet I don’t use mouse rather I use vimperator and within VS.NET I use ViEmu. So for VS.NET I am always looking for keyboard shortcuts for the things that I cannot do through ViEmu. To do that in VS.NET I would have jump through hoops to figure out a keyboard shortcut for a command, I would have to navigate to Tools/Options/Environment/Keyboard, which is a pain.
There is also a plugin for ReSharper to do the same.
So I wanted something like the plugin, but something that I can query for. So I was planning to write one ,as a Visual Studio addin which is supposed to couple of things
- Pass a partial command name , which returns list of commands and their corresponding keyboardshortcuts
- Pass a Partial keyboardshortcut , which returns list of commands that have the keys as binding
And that’s when I stumbled upon Accessing Visual Studio’s Automation API from F# Interactive . That’s awesome and it gives the great power for automation with succinct code.
Here is the code for doing the things that I wanted to write
let convert (c:Command) = ((c.Bindings) : ?> System.Object[] |> Seq.cast<string>) let keymapsearch key = myDTE.Commands |> Seq.cast<Command> |> Seq.filter(fun k -> convert k |> Seq.exists(fun k -> k.Contains(key))) |> Seq.map(fun k -> (k.Name, (convert k ) |> Seq.head)) let commandkeysearch c = myDTE.Commands |> Seq.cast<Command> |> Seq.filter( fun k -> k.Name.StartsWith(c)) |> Seq.map( fun k -> (k.Name, convert k ))
FYI this code has to be sent to interactive FSI window within Visual Studio .NET and to use this you would still rest of the code which is available from the original post.
And here is the usage of the above functions
commandkeysearch “Debug.Bre”
>
val it : seq<string * seq<string>> =
seq
[("Debug.BreakAll", seq ["Global::Ctrl+Alt+Break"]);
(“Debug.Breakpoints”, seq []); (“Debug.BreakInFile”, seq []);
(“Debug.BreakatFunction”, seq []); …]
keymapsearch “Ctrl+F5″
val it : seq<string * string> =
seq
[("Debug.StartWithoutDebugging", "Global::Ctrl+F5");
("Data.SqlEditorValidateSqlSyntax", "Transact-SQL Editor::Ctrl+F5")]
The automation provides REPL to VS.NET which is really handy.

[...] This post was mentioned on Twitter by Naveen. Naveen said: Visual Studio Keymaps using F# http://bit.ly/atXtJl [...]
Tweets that mention Visual Studio Keymaps using F# « Naveen's Blog -- Topsy.com
May 16, 2010 at 12:58 am
Nice. Thanks for sharing :)
Kurt Schelfthout
May 16, 2010 at 3:59 am
[...] Over on Naveen’s Blog there is a post Visual Studio Keymaps using F#. [...]
Visual Studio Keymaps using PowerShell
May 16, 2010 at 2:45 pm
[...] Visual Studio Keymaps using F# « Naveen's Blog [...]
Tutorial 1 – Visual Studio 2008, Linq to SQL, C#, and WPF … | C# WebDev Insider
May 24, 2010 at 7:09 pm