I’ve written an earlier article here about using the keyboard to navigate around Visual Studio. I’m a nut for not having to move my hands to grab the mouse for tasks which could be done via the keyboard. Reaching for the mouse busts up my train of thought and slows me down, neither of which I care for.
For this installment of Ask The Pros I thought it would be interesting to get feedback from industry leaders on what their most-used and favorite keyboard commands are. Contributors to this round of the series are:
- James Avery, Principal of Infozerk, Inc., author of Visual Studio Hacks, and host of this website
- Dave Donaldson, President/CEO of Arcware, Inc. and creator of CodeKeep
- Mike Gunderloy, Owner of Lark Group, Inc., publisher of The Daily Grind, and prolific author
- Scott Hanselman, Chief Architect at Corillian Corporation, a leading provider of eFinance solutions
- Roy Osherove, Principal of Team Agile located in Israel, and a consultant for Agile software development and .NET Specialist
Keyboard Shortcuts
James Avery is an unabashed nut for Intellisense. “If there was a steel cage match of keyboard shortcuts there would be one clear-cut winner: Ctrl-Space. Sure there are other useful shortcut keys, but Ctrl-Space makes one of Visual Studio’s most useful features even better; it summons Intellisense wherever you are.” Avery lists off several of what he considers Intellisense’s best uses: “Sitting on a blank line of code? Ctrl-Space will bring up Intellisense. Want to see all your private member variables? Enter your prefix (_, m_, etc) and then hit Ctrl-Space, now you have a nice filtered list.”
Avery notes an extremely useful, but often overlooked bit of goodness when trying to find method documentation with Intellisense, “Most people will delete a comma or opening parenthesis to see the method documentation, but you can simply Ctrl-K, Ctrl-P.”
Scott Hanselman likes the very basic keystrokes supporting Copy/Cut/Paste within Visual Studio. “I’m pretty much a CtrlX,C,V person along with Shift-Ctrl-B within Visual Studio.” He goes off the deep geekiness end, though, by having tacked on an Ergodex input system to “map more complicated combinations (because I can’t hold them in my head) to a single custom labeled button.” Hanselman wrote a blog post describing his use of the Ergodex and how its mapping ability may transform his work.
Hanselman pointed out great keyboard shortcuts outside Visual Studio which can bring great boosts in productivity. “I’m all about the Windows Key, using Windows-Q to bring up SlickRun from Bayden Systems. In Word I tend to do Alt-V,U,Alt-VZ,T,Enter very quickly to show documents full screen for presentations. In Windows I use Ctrl-Space,N to minimize a lot, and in the Command Prompt I use Ctrl-Space,E,P and for pasting directly to the command line.”
In a bit of useful advice for folks trying to fend off carpal tunnel syndrome, or any of the other various repetitive motion injuries, Hanselman says, “I try to stay balanced in my use of the keyboard vs. the mouse.”
Dave Donaldson points out another little-known shortcut that boosts productivity for folks working in Test Driven Development environments: “Ctrl+M, K – Generate Method Stub (VS 2005). As someone who uses a test-first approach in development, the ability to write a unit test and then hit Ctrl+M, K to generate the signature of my implementation method is rockin. It’s something that most people don’t know is there, but I find a killer shortcut in a TDD environment.”
Reading someone else’s code is something everyone has to do, and it can be an infuriating task, especially if the person who wrote the code had different conventions and styles than you. Visual Studio 2005’s ability to format code with different styles is a terrific feature, especially since you can quickly format a document in your style: “Ctrl+E, D – Format Document (VS 2005). I look at tons of code that is not mine, and having a quick way to format the code according to my settings is very useful. For instance, I like my opening curly brace on the next line of the method signature. However, if I look at someone’s code who types with the opening curly brace on the same line of the method signature, I simply hit Ctrl+E, D to format the code file using my settings.”
[For more information on how to set formatting options in Visual Studio, see James Avery’s Tip on C# Code Formatting.]
Donaldson’s next tip is in the same code reading line: “Ctrl+M, P – Stop Outlining (VS 2005, VS.NET 2003). As useful as code regions are, there are times when I just want to expand all regions to scroll through the code. To do this, I hit Ctrl+M, P to turn off outlining, which expands all the regions.”
Donaldson finishes off with something near and dear to every developer’s heart: “F5 – Start Debugging (VS 2005, VS.NET 2003, and previous versions). Enough said.”
Roy Osherove starts off with a favorite of mine, the Clipboard ring. “The clipboard ring is not very well known, but very powerful:
Pressing Ctrl-Shift-V repeatedly pastes in the last ten “Copy” operations you’ve made, saving you precious time.” He also notes that “Ctrl-Alt-X: the tools window (which allows you to see the Clipboard ring in vs 2003). Pressing Ctrl-DownArrow and UpArrow shifts between the open tools tabs in that tool window.”
Moving around to spots in the editor windows you’ve been is made simple by using “Ctrl–(minus) and Ctrl-Shift–: gets you back and forth in the location history of the editor.” Osherove points out another useful movement keystroke: “Escape – useful. Always makes the code view or current document in the tab active, no matter what tool window is active at the time.”
Two quick keystrokes save Osherove time when bouncing to specific windows. “Ctrl-Alt-S brings up the server explorer,” and “Ctrl-Alt-O: the output window.”
Osherove’s last tips deal with working with code in an editor window. Commenting out blocks and un-commenting them again are serious drudgework greatly eased by “Ctrl-K-C and Ctrl-K-U to [C]omment and [U]ncomment code blocks.” Finally, “Ctrl-Shift-Space – shows the parameter list for a method call. Saves the time going back, deleting and reentering a command after the last parameter. Phew! (If you have resharper installed, it’s Ctrl-P.”
Macros
Macros don’t seem to have much regular use with this round’s responders. Perhaps macros aren’t particularly useful in day-to-day work and just solve occasional tricky problems. Hanselman notes “I have lots of macros, but they are the kind that you use once in a blue moon. I haven’t any macros that I use daily.”
Keybindings
Avery’s favorite keybindings involve wiring up a great addin to Visual Studio: Roland Weigelt’s GhostDoc. “Nothing like having the commands on keystrokes to make that useful add-in even more useful.”
Many Visual Studio developers might not realize how many shortcut commands are available to them for custom binding. Osherove gives some great advice. “The best thing you can do for yourself is look at all the currently available shortcuts by clicking Tools-Options-Keyboard and looking for whatever command you like. You can also map shortcuts to any command (or multiple shortcuts to a single command).”
And Finally
Not all highly-skilled developers are fixated on making the most of the keyboard. Gunderloy spends his days using a tremendous number of tools. So many, in fact, that he doesn’t take time to learn shortcuts. He says “If it wasn’t for typing code, I’d never touch the keyboard at all. I know it puts me at odds with most experts, but I drive the UI with the mouse, period. I can’t be asked to learn keyboard shortcuts or set up custom key bindings; I spend too much time switching between too many different programs all day long.”
