"Remove and Sort" namespaces using shortcut in Visual Studio

August 06, 2014 by Anuraj

.Net Visual Studio

If you are using StyleCop for maintaining C# coding standards and conventions, we used to do Remove and Sort namespaces feature from Visual Studio. The Organize Usings options in the Visual Studio integrated development environment (IDE) provide an easy way to sort and remove using and extern declarations without changing the behavior of the source code. Over time, source files may become bloated and difficult to read because of unnecessary and unorganized using directives. The Organize Usings options compact source code by removing unused using directives and improves readability by sorting them. I am huge fan of keyboard shortcuts, but by default VS did come with a keyboard shortcut for this feature. This post is about adding a keyboard shortcut to Remove and Sort.

We can set the keyboard shortcut by using Tools > Options. And select the Keyboard option. In the Show commands containing textbox, search for “Edit.RemoveAndSort”, this command will do the removing and sorting of namespaces, set shortcut for the same using Shortcut keys textbox and assign text box. Currently I am using “Ctrl + Shift + K” for this. Click Assign and OK.

Remove and Sort - Keyboard shortcut assignment

Next time you can simply using “Ctrl + Shift + K” shortcut for removing and sorting namespaces.

Happy coding :)

Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub