(This is a part of my series Visual Studio Tips and Tricks – IX)
Do you find your code messy, especially in the using directives section? When adding a new .cs file, by default certain namespaces are automatically added, but there are times when you will not use them. Following is the screenshot if you are using Resharper plugin in Visual Studio.
Note any differences? You will see that I only make use of one namespace which is System (System.Console) while the rest of the namespaces are not in use. Resharper being intelligent dims the unused namespaces as shown above.
Hovering at the using directives sections, Resharper prompts me with a red bulb and asking me whether to remove the unused directives in file. Clicking it will remove the unused directives.
The same can be accomplished without using any plugins in Visual Studio by right clicking the code editor and choosing Organize Using > Remove and Sort.
Open Tools > Options menu. Select show all settings. Select Environment > Keyboard. Then type Organize to filter the commands in Show commands containing.
Then choose EditorContextMenu.CodeWindow.OrganizeUsing.RemoveAndSort and press Ctrl + U in Press shortcut keys text box. You will see that Edit.MakeLowercase already makes use of that shortcut key. Since I never use that keyboard shortcut, I prefer to replace it. Search again for Edit.MakeLowercase and click the remove button to remove the Edit.MakeLowercase keyboard shortcut.
Search back again for Organize and choose RemoveAndSort and assign Ctrl + U. Next time you want to organize using directives its as simple and as fast as pressing Ctrl + U.
If you would like to see more Visual Studio tips and tricks page. Please visit Visual Studio Tips and Tricks.