views:

200

answers:

2

I am a bit lazy when it comes to formatting code in Visual Studio and almost rely solely on the magic of Ctrl + K, Ctrl + D (or F depending on what I’m doing). However I loathe having to use my right mouse button to Remove and Sort my using statements and am constantly forgetting.

Assuming that I’m not using Re-Sharper is there any way to extend the Ctrl + K, Ctrl + D keyboard shortcut to format my code and sort my using statements?

Would writing a macro to do both tasks and assigning it the same key combination the only way to do it?

+4  A: 

It's not extending the current key combo as such, but there's a Edit.RemoveAndSort command to which you can assign a key binding in Tools -> Options -> Keyboard.

Here's a blog post detailing just that.

Phil Jenkins
I know that it sounds petty but I really wanted something that would do both Edit.RemoveAndSort as well as Edit.FormatDocument
Kane
A: 

From the lack of response I can only assume that I'll need to create a macro and assign it the same keyboard shortcuts... oh well

Sub LazyFormatAndSortUsingMacro()
    DTE.ExecuteCommand("Edit.FormatDocument")
    DTE.ExecuteCommand("Edit.RemoveAndSort")
End Sub
Kane