What keyboard shortcut is there to organize C# usi

2020-02-26 02:35发布

问题:

Is there a way to organize C# usings (remove and sort, in separate or together) via a shortcut in Visual Studio for one or more files of a project?

I know that this can be done via the menu for one file by selecting

Edit > IntelliSense > Organize Usings > Remove and Sort

but I want to do this much faster. I am using Visual Studio 2013 Express for C# development (wondering how this can be done in older & other versions too though). Thank you in advance.

回答1:

Go to Tools => Options => Environment => Keyboard

Enter the key combination you want to use (click the Press shortcut keys: textbox, press your key combo as you would execute it while editing)

Then type "usings" in the Show commands containing: textbox

And now you can assign whichever version of these remove/sort usings commands that you like to the key combination.

This works for pretty much every command in Visual Studio, and from any addons you have installed. Just type a word involved in the command name to find the command. Assign away!



回答2:

Since VS2017, it's a builtin shortcut. Simply press Ctrl + R, Ctrl + G. Credit goes to Emanuel Ve, who mentioned this first in the comments; I'm putting the advice into an answer for greater visibility.



回答3:

In addition to @Will's answer, Productivity Power Tools is a great addon that has all this - and lots lots more!