Continuing with our series of becoming a keyboard ninja.
Creating New Items!
Lets start with an empty MVC shell. If you don’t have MVC 3.0 installed yet, you probably should, since we will be referencing it a lot.
The age old right click on folder in the solution explorer “Add-> New Item…” is not for the Keyboard Ninja! Same for the “File ->New -> File”. It takes far too long and way too much clicking and scrolling with the mouse.
Of course some may say, could it be that “Ctrl – N” maybe of service, but I say no! Try it yourself, first we get the select file type screen, of course what we usually use is not the default highlight. After selecting the “Visual C# Class”, we get a clean class called “Class1″. But no file in sight, and the cursor at the top of the file, things are not much better than with a mouse click. (the second time with “Ctrl – N” did save the last file type used)
And then there is “Ctrl – Shift – A”, add new item shortcut. It’s not a bad choice if you don’t have ReSharper and you can control the Visual Studio default templates. You can locate and organize project templates, easily edit, and create item templates. It’s a lot easier if you have ReSharper and use the Live Templates feature.
Now lets try my favorite way,” Ctrl – Shift – Ins”. The ReSharper insert template, awful to remember, but we will remap “Ctrl – N” to the this command later on. First press “Ctrl – W – S”, which will either show or focus on the solution explorer, easy way to remember is “W” -> window, “S” -> solution explorer. Select the folder “Controllers” and “Ctrl – Shift – Ins”. Select the “Class” as the template. You can also hit the underlined letter key to insert the template without having to navigate to it, in this case “l”. I am naming mine as “AccountController”. Extend the “Controller”, which will result in a blue pop up to add a reference with “Alt -Enter”.
“Alt – Enter” will be the most used shortcut in the process of programming. This brings up the smart ReSharper options, which officially stands for “ReShaper_ForceCompleteItem”. The short cut works whenever there is a ReSharper menu icon pops up on the left hand side of the code.
Let’s remap “Ctrl – Alt -Ins” to an easier to remember and use “Ctrl – N”. Open the “Tools -> Options -> Keyboard”, and find out what the command for the ReSharper insert template, go to the “Press shortcut keys:” and the command will show up in the “Shortcut currently used by:” dropdown. There is a dropdown because the same keystroke can do different things in different scopes. “Global” applies to shortcuts at any level, “Text Editor” only in text edit mode.
The command is “ReSharper.ReSharper_GenerateFileBesides”, lets find it and reassign “Ctrl – N” to that. Go to “Show commands containing:” and start typing in “GenerateFile” the command will become highlighted. The search box is an auto search and its an insensitive contains, so you don’t have to know the exact command to find it. In the “Shortcuts for selected command:” dropdown you will find all the current shortcuts assigned to the command. We are going to add a new one. Go back to “Press shortcut keys:” and “Ctrl – N”, you may get the double shortcut of “Ctrl – Alt – Ins, Ctrl – N”, press “Ctrl – N” again to reset the dialog. Keep “Global” in the scope dropdown and click “Assign”.

Check if the “Ctrl – N” is the right shortcut, by pressing the shortcut keys in “Press shortcut keys:” and checking the currently used by dropdown. There are two items in my list, one is the global ReSharper generate file and the other “SqlEditorNewQuery” in the “Transact-SQL Editor” scope. Since that will not interfere with the new command I will not remove the assignment. If you wanted to remove the command, then you would have to search for it, and select the shortcut you would like to remove in the dropdown menu and click “Remove”.
Most of the time I am in the middle of class creation when I run across the need for a new class or interface. For our example lets create “AccountService”, that will implement the “IAccountService” interface. Instead of using our newly created shortcut we will just start typing the new interface in as a constructor dependency for our Controller.
“pu” “Tab” will autofill “public”, “Accou” “Tab” will autofill “AccountController”, “(IAccountService accountService)” “Enter” “{“, the auto fill will put in our closing curly brace. The “IAccountService” will appear red, since we do not have that class, navigate to the “IAccountService” and you will see the red ReSharper can do something about this box, press “Alt – Enter”.
Select create interface(notice the underlined characters), the interface is created at the bottom of the file. Put cursor on the name of the new interface, a new box will appear, a purple pyramid. “Alt – Enter” and select “Move to another file and match type name”. Now you have a new file, and can be done quickly and efficiently. The only downside, the new file probably does not belong in the same folder. And so far I have not discovered a way to move the file without drag and drop. Once in the right folder, you will have an option to adjust the namespace by “Alt – Enter” on the namespace.
Next: Refactor Options






