Naveen's Blog

Software dev interested in .NET, windbg and anything on the way

Visual Studio Keymaps using F#

with 4 comments

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

  1. Pass a partial command name , which returns list of commands and their corresponding keyboardshortcuts
  2. 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.

About these ads

Written by Naveen

May 16, 2010 at 12:03 am

Posted in F#, VS2010

4 Responses

Subscribe to comments with RSS.

  1. [...] This post was mentioned on Twitter by Naveen. Naveen said: Visual Studio Keymaps using F# http://bit.ly/atXtJl [...]

  2. Nice. Thanks for sharing :)

    Kurt Schelfthout

    May 16, 2010 at 3:59 am

  3. [...] Over on Naveen’s Blog there is a post Visual Studio Keymaps using F#. [...]

  4. [...] Visual Studio Keymaps using F# « Naveen's Blog [...]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: