Posted by Anuraj on Wednesday, August 6, 2014 Reading time :1 minute
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.
Next time you can simply using “Ctrl + Shift + K” shortcut for removing and sorting namespaces.
Happy coding :)
What do you think? I would like to hear your thoughts, suggestions, and questions in the comments section below.