How to setup ReSharper to call "Sort usings" in class?
5 Answers
I will answer for my question.
Using shortcut from Resharper it's not best solution. Nice tool is CodeMaid it makes few nice cleanup's when saving file like with no shortcut key press:
- sorting usings alphabetically and remove unused
- deleting empty lines
This tool is complement for Resharper.

- 1,423
- 2
- 14
- 21
Resharper (9) will sort usings if you run Code Cleanup, via menus or keyboard shortcut CTRL+E, CTRL+C

- 7,780
- 3
- 46
- 42

- 881
- 10
- 14
Try using the Stylecop Resharper Plugin
Stylecop Rule SA1210: Using directives must be sorted alphabetically by the namespaces
will allow you to use a quick fix to sort them by pressing ALT+ENTER.
Using Stylecop is good at helping you write clean code, but you may want to turn off some of the rules.

- 7,780
- 3
- 46
- 42

- 10,611
- 6
- 46
- 61
-
7+1 It is easy to use StyleCop to waste your time if you have too many rules turned on. – Keith Pinson Jun 20 '13 at 18:31
You don't need ReSharper to do this. By Default the shortcut CTRL+E, R will remove (unused) and sort the using statements.
If you only want sorting or the shortcut isn't set on your instance of Visual Studio, go to:
- Tools-> Options.
- Environment -> Keyboard
- Search for "Editor.ContextMenus.CodeWindow.OrganizeUsings".
There are a few options there to play with.
-
This doesn't really work - resharper overrides the newly bound shortcut every time after I press "OK". – tkit May 08 '15 at 10:24
-
3This is probably dependent on the version of VS and ReSharper. Couldn't get this keystroke to work. However, clicking on the USING statement with resharper pops up a lightbulb icon, which includes the option to remove and sort. – RaoulRubin Jan 01 '16 at 14:25
-
2In Visual Studio 2017 the name changed to: "EditorContextMenus.CodeWindow.RemoveAndSort" – Lech Osiński Jan 02 '19 at 14:14
-
-
@DannyThunder - The name is still "EditorContextMenus.CodeWindow.RemoveAndSort" even in Visual Studio 2022. The one you mentioned "Edit.SortUsings" only sorts, and is not removing unused ones. – Lech Osiński Jan 04 '22 at 16:01
This question already covers this:
Remove unused Usings across entire assembly
The feature is in ReSharper 4.5. If you right click on the solution, there's a Cleanup Code... item, which allows you to apply a cleanup profile to the solution. You can create a new cleanup profile from the Code Cleanup node within ReSharper options, if you want a profile to just adjust the using directives.
-
1
-
Do you mean alphabetically "sort" then? Your question is very vague..! I thought you mean sort as in "sort out"! Sorry if I misinterpreted. – Bex Nov 09 '11 at 13:11
-
1