"Remove and Sort" namespaces using shortcut in Visual Studio

Posted by Anuraj on Wednesday, August 6, 2014

.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 :)



Did you like this article? Share it with your friends

Facebook Twitter Google+ LinkedIn Reddit StumbleUpon



MVP
Subscribe


Copyright © 2017 - Anuraj P. 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. Hosted with ❤ by GitHub