I’m a keyboard kind of guy. I hate it when I have to put my hands on the mouse – it
slows me way down. So it should be no surprise that I’m a fan of emacs – keystrokes
for everything. Still, I tend to use VS.NET, because it’s got a bunch of stuff that
I can’t get (yet) in emacs, like Intellisense and integrated debugging.
As a result, I’ve made an effort to learn VS.NET shortcut keys. I find myself often
pointing these out to fellow developers, especially when I’m suffering, watching them
laboriously navigate the menu system or type with one hand. Here are my favorites.
Some of these have already made the blogging rounds, but hopefully you’ll find at
least one gem in here
Key sequence
|
Command
|
Description
|
Ctrl-minus
|
Source “Back”
|
Works like your browser’s “back” button – takes you to the last line of code you were looking at, whether it’s in a different file or the file you’re currently in.
|
Ctrl-shift-minus
|
Source “Forward”
|
Works like your browser’s “forward” button. Opposite of ctrl-minus.
|
Ctrl-k Ctrl-k
|
Toggle bookmark
|
Adds or removes a bookmark to the current line. I use this one frequently when adding a using statement to the current file. Set a bookmark so I don’t lose my place, go to the top of the file (ctrl-home), add the using statement, then jump back to the bookmark.
|
Ctrl-k ctrl-n
|
Go to next bookmark
|
Navigates to the next bookmark. Because this gets annoying when there are lots of bookmarks in the file, I generally toggle the bookmark off as soon as I get back to it.
|
Ctrl-i
|
Incremental search
|
Incremental search is a great way to search really quickly: you type ctrl-i and then immediately start typing the word you’re looking for. As you type each letter, VS.NET will find the first instance of what you’ve typed so far. So, for example, if you’re looking for “foo”, you type ctrl-i, then “f”, and it will find the first instance of “f”. Then you type “o” and it will find the first instance of “fo”. If that’s “foo”, you’re done. If it’s “for” you can either type “o” again to look for “foo” or type ctrl-i again to look for the next instance of “fo”. Emacs has had this forever, but it’s nice to have it in VS.NET, too.
|
Ctrl-a Alt-e v b
|
Select all, Untabify
|
Turns all tabs into spaces. Useful when I’m pasting code into an email or Word.
|
Ctrl-a Ctrl-k Ctrl-f
|
Select all, reformat
|
Ctrl-k ctrl-f will “reformat” the selection, making sure all the code is properly indented and even “fixing” which line the curly-braces appear on (you can set your definition of “correct” in VS.NET preferences).
|
Ctrl-k Ctrl-c
|
Comment selection
|
Puts “//” comments in front of whatever text is currently selected.
|
Ctrl-k Ctrl-u
|
Uncomment selection
|
Removes “//” comments from the front of whatever text is currently selected
|
Ctrl-J
|
List members
|
Pops up the Intellisense list that you normally get when you hit “.” after a variable. Very useful if you’ve navigated away from the list and you want to get it back.
|
Ctrl-shift-space
|
Parameter Info
|
Pops up the method information list you normally get when you hit “(“ after typing a method name in. I use this all the time, as I often start typing in the method’s parameters, then have to go do something else, like read the help. When I come back, this key sequence lets me pop up the completion list again.
|
F12
|
Browse definition
|
Jumps to the definition of whatever the cursor is on. Useful for when you’re thinking, “Umm, what does this method do?” Combine with ctrl-minus to jump right back to where you were.
|
F7
|
View code
|
VS.NET often insists on showing me the stupid designer view when what I want to see is the code. F7 shows me the code.
|
Shift-F7
|
View designer
|
Sometimes I actually do want to see the designer. This will show it to me when I’m in the corresponding code file.
|
Those are the main ones that I use day-to-day. There are many, many more – I find
it really useful to browse through the Tools->Customize->Keyboard dialog every
once in a while, looking for good ones (the keyboard shortcuts show up in “Shortcut(s)
for selected command”).
If you're accepting submissions, my personal favourite is Ctrl-M, Ctrl-O to collapse the outlines, followed by Ctrl-M, Ctrl-M to expand a specific section... really helps me zip around big source files.
ReplyDeleteEditing the entry is a PITA, so go ahead and post suggestions here as comments (like you've done).
ReplyDeletePersonally, I can't say I care for the outlining stuff too much. It's just personal opinion, but popping the damn things open and closed is more trouble than just doing an incremental search for the name. What they really need is a keystroke that will navigate me to a method by name - sort of like a scoped incremental search.
Anyway - thanks for the suggestion, I know a lot of people use outlining.
Ctrl-Shift-Enter. Toggles Full Screen mode. Invaluable for demos.
ReplyDeleteGood one, although I believe it's Alt-Shift-Enter to go fullscreen.
ReplyDeleteI also forgot Shift-Enter and Ctrl-Shift-Enter, which are "insert new blank line above/below current line" (respectively).
My personal favorite is Ctrl-T for transpose the two characters the cursor is sitting between, and Ctrl-Shift-T to transpose words. I get stuff out of order all the time.
ReplyDeleteThe only weird thing is that the transpose words command swaps the next two words ahead of the cursor, instead of the words the cursor is between.
Another great emacs feature absorbed. :)
ReplyDeleteA classic Ctrl-K Ctrl-D will pretty format an xml document.
ReplyDeleteYeah, although it kills blank lines between elements, which I hate. I like to use vertical whitespace to keep things readable, and C-k C-d eats it. :p
ReplyDeleteThese shortcuts are fabulous.
ReplyDeleteCan anybody tell me the shortcut for Opening and closing the regions of the code?
Thanks in advance
Ctrl-M Ctrl-M
ReplyDeleteCtrl-M Ctrl-L
Ctrl-M Ctrl-O
Depending on what you're trying to do.
Great shortcuts. Is there a keyboard shortcut to collapse all the projects when you open a solution with multiple projects...within the solution explorer...
ReplyDeleteI'm not aware of one. Love to know what it was if such a beast existed, though.
ReplyDeleteGenerally, I find that Ctrl-Alt-L followed by repeated {left-arrow down-arrow} is quick enough.
The Expand-All and Collapse-All shortcuts in the Solution Explorer are * and - in the number pad.
ReplyDeletectrl+ F4: close the active windows of the code inside the project.
ReplyDeleteVery useful to close fastly all the windows.
crtl+tab: alternate window inside the project.
ReplyDeleteWhat is the shortcut key for "Find All References" for particular property/method name? We can select a particular word under the cursor with Ctrl W.
ReplyDeleteShortcut key for "Find All References" : on a particular word use SHIFT+F12
ReplyDeleteALT+W+L will close all opend windows.
ReplyDeleteFor a complete list of shortcuts for Visual Studio 2008:
ReplyDeletehttp://franzhemmer.blogspot.com/2008/11/visual-studio-2008-keyboard-shortcuts.html