336
votes

What is your favorite Visual Studio keyboard shortcut? I'm always up for leaving my hands on the keyboard and away from the mouse!

One per answer please.

13
  • Same questions have been asked here : stackoverflow.com/questions/20507/… and here : stackoverflow.com/questions/26452/visual-studio-2005-shortcuts Sep 19, 2008 at 3:22
  • the correct thing to do is relate these by tagging them similarly Mar 10, 2009 at 22:57
  • 2
    I think that's a load. I am much, much faster using only the keyboard than the mouse. I in fact HATE my mouse. Sucks that it is a necessity. Nov 14, 2009 at 14:52
  • 11
    @DanM, anything that "Apple proved" needs to be taken with a grain of salt. How is hunting for and moving the mouse to a small patch of pixels ever going to be quicker than a memorized key shortcut? Seriously, get your hand of it and back onto the keyboard ;)
    – Ash
    Jan 29, 2010 at 4:32
  • 2
    @DanM, its not an all or nothing scenario. Using cursor keys to move to arbitrary positions in a document is silly, use the mouse. But as you get more experienced with shortcuts, keys are simply quicker for most other things. With the mouse, you're also having to deal with hand eye coordination, meaning it can be very fiddly. Suggestion: Try to focus on using keys more, for a month or so. You may find it hard going to start with, but your productivity will greatly benefit if you stick at it. But sticking at it is the key.
    – Ash
    Jan 29, 2010 at 8:10

124 Answers 124

1
2 3 4 5
227
votes

Ctrl + - and the opposite Ctrl + Shift + -.

Move cursor back (or forwards) to the last place it was. No more scrolling back or PgUp/PgDown to find out where you were.

This switches open windows in Visual Studio:

Ctrl + tab and the opposite Ctrl + Shift + tab

9
  • 18
    I've been looking for this forever. I used to just use Ctrl+Z Ctrl+Y. Apr 23, 2009 at 19:49
  • 4
    Ctrl-Tab is a bit funny in VS for some reason - it doesn't just cycle like most apps. Jul 1, 2009 at 21:28
  • 6
    @Lucas Jones, It seems to cycle like Alt-Tab in Windows. Seems normal to me.
    – devuxer
    Sep 28, 2009 at 23:59
  • 4
    Pressing Ctrl + Tab once swaps between the current document and previous document, you don't even need to look at the popup window.
    – Ash
    Jan 27, 2010 at 5:00
  • 3
    I often cancel cycling between application windows (Alt+Tab) by pressing Esc. Doing so while cycling through document windows (Ctrl+Tab), however, pops up Windows' start menu. That just drives me nuts.
    – sbi
    Jun 2, 2010 at 10:50
130
votes

For me, it's nothing to do about auto completing code, matching parenthesis or showing some fancy tool panel. Instead, it's just about letting me see the code.

With all the panels surrounding you, the area you use to actually write code becomes too small.

In this cases, Shift+Alt+Enter comes in to the rescue and gets the code window in focus in full screen mode. Hit it again, and you have all the panels back.

4
  • I always use Alt+V, U for the same effect :) But yeah fullscreen mode rocks.
    – korona
    Nov 7, 2008 at 8:37
  • 17
    BIG monitors work too =)
    – Beep beep
    Mar 11, 2009 at 1:33
  • Agreed! I use this one all the time. VS10 will have floating panels which will help somewhat.
    – Paul
    Oct 28, 2009 at 5:11
  • Having all the extra windows unpinned when in edit mode helps too. Jan 22, 2010 at 15:08
124
votes

Incremental Search - Ctrl + I

It's basically the find dialog box without the dialog box. Just start typing what you want to search for (look at the bottom status bar location to see what you've typed). Pressing Ctrl + I again or F3 searches for the next instance. Press Escape to quit. Starting a new search by pressing Ctrl + I twice repeats the last search.

8
  • Plus, it finds the first instance as you type. Ctrl-i after you hit a match searches to the next instance - and keeps you in search mode (which means you can add or change the search string). The search box is for suckers!
    – Aardvark
    Oct 4, 2008 at 19:59
  • 9
    One caveat with this that I've seen (in VS 2005 any way), it only searches through visible text. So if you have some collapsed in a region, for example, it won't search that. I don't know if this is a feature or a bug!
    – Adam Neal
    Jan 7, 2009 at 21:00
  • 1
    Sounds like the emacs search feature.
    – dicroce
    Mar 10, 2009 at 23:15
  • 2
    @CodeSavvyGeek: It's fixed in VS2010. Jun 28, 2010 at 18:36
  • 1
    Actually, it is now in 2012 kind of merged with search(ctrl+f) into one feature
    – Marko
    Jul 13, 2012 at 14:47
98
votes

Expand Smart Tag (Resolve Menu): Ctrl + . (period)

Expands the tag that shows when you do things like rename an identifier.

6
  • Best shortcut ever. Use when you see a squiggly "~", under some code. : )
    – Chad Moran
    Mar 4, 2009 at 21:59
  • 1
    This is my fave and only one I can remember. Alt-Enter is similar if you have resharper installed.
    – Daniel
    Mar 10, 2009 at 20:14
  • 6
    Also Shift-Alt-F10 is bound to this but probably harder Jun 26, 2009 at 11:35
  • Good shortcut, but what it actually does is bring up the "Resolve" menu (so you can add a using statement or fully qualified namespace for a class)...it has nothing to do with tooltips.
    – devuxer
    Sep 29, 2009 at 0:10
  • DanThMan, you're right, tooltip isn't the correct terminology, will update
    – Ray
    Oct 14, 2009 at 1:43
95
votes

Ctrl+K, Ctrl+C Comment a block

Ctrl+K, Ctrl+U Uncomment the block

5
  • Ctrl K, D formats the entire document (proper indents, ws cleaned up, etc.) in mine. ? Oct 21, 2008 at 20:40
  • I typically customize the mapping to be CTRL+/ (comment) and CTRL+SHIFT+/ (uncomment). I find that nice and intuitive.
    – el2iot2
    Jan 25, 2009 at 21:53
  • 8
    Ctrl-E, C and Ctrl-E, U also works. You dont have to release Ctrl after the first key either.
    – geofftnz
    Feb 9, 2009 at 20:24
  • 2
    I use CTRL+/ withy Resharper.Resharper_LineComment which with one shortcut toggles line comments on and off.
    – Myster
    Sep 28, 2009 at 22:47
  • I use this often so I like to customize this as well to something easy on the fingers: Alt-[ to uncomment, and Alt-] to comment. Jan 4, 2013 at 0:05
77
votes

Stock Visual Studio? F12 - Edit.GoToDefinition.

Having DevExpress' Refactor! installed means that Ctrl + ` is my all-time fave, though ;)

2
71
votes

The TAB key for "snippets".

E.g. type try and then hit the tab key twice.

Results in:

try 
{           

}
catch (Exception)
{

    throw;
}

which you can then expand.

Full list of C# Snippets: http://msdn.microsoft.com/en-us/library/vstudio/z41h7fat.aspx

1
  • 2
    Fantastic - knew about snippets, but not that you could get to them so quickly!
    – xan
    Mar 25, 2010 at 15:26
61
votes

Ctrl+] for matching braces and parentheses.

Ctrl+Shift+] selects code between matching parentheses.

2
  • 1
    Unfortunately, unlike most other keyboard shortcuts this one is language neutral. For example on a Danish keyboard it is CTRL+Å. For all the different ones see this StackOverflow question: stackoverflow.com/questions/1501921/… Sep 9, 2011 at 13:14
  • wow this one is great for looking through loooong lines of code someone else wrote Jul 29, 2013 at 15:27
60
votes

Ctrl+Shift+F

Good old Find In Files.

0
51
votes

Ctrl+Space, Visual Studio gives the possible completions.

47
votes

Ctrl+K, Ctrl+D // Auto-(Re)Format

See Also: Answer

3
  • Particularly useful for messy XML files. Nov 5, 2009 at 11:29
  • to my VS, is CTRL + K, CTRL + Y :)
    – Elaine
    Jun 16, 2011 at 7:07
  • and for me it's CTRL + K, CTRL + F Oct 23, 2013 at 15:46
43
votes

Ctrl+C, Ctrl+V to duplicate the current line

Ctrl+L to delete the current line

Ctrl+F3 to search for the current selection

Ctrl+K, Ctrl+K to create a bookmark (which are useful)

Ctrl+K, Ctrl+N to go to the next bookmark

And, here is something even more interesting:
Press Ctrl+/ to put the cursor into a box where you can type commands.

For example, Pressing Ctrl+/ and type ">of ", now start typing the name of a file in your project, and it will autocomplete. This is a very fast way to open files in the current solution.

8
  • 11
    Control-L cuts the current line. Control-Shift-L deletes it.
    – Greg
    Nov 3, 2008 at 14:52
  • 2
    @Greg: Class, thanks. @Others: These are great ones, but fail to adhere to the questioner's one per line ask :- -1 :( Jun 26, 2009 at 15:19
  • Also dup of stackoverflow.com/questions/98606/… Jun 26, 2009 at 15:23
  • Ctrl + D duplicates the current line as well (and much shorter)
    – Ray
    Oct 14, 2009 at 1:39
  • 1
    @Ray: Ctrl + D isn't working for me. Is that with default Visual Studio shortcuts? It might be a ReSharper shortcut IIRC?
    – dariom
    Oct 1, 2010 at 8:30
40
votes

Ctrl+Shift+V paste / cycle through the clipboard ring

4
  • I've always found this feature too slow to be of any use. I wish they would improve its performance - sometimes its takes up to 20 seconds to load the items in the clipboard.
    – cbp
    Apr 6, 2009 at 5:09
  • Use clipx if you want to do clipboard history. It spans all applications. bluemars.org/clipx
    – Tim Coker
    Jul 22, 2010 at 16:44
  • in 2012 working great! than you :)
    – Marko
    Jul 13, 2012 at 14:50
  • Wow this is awesome. This is a nice helper for all those times I thought I had "lost" my previous clipboard contents, it was still there the whole time. Thanks! Dec 7, 2012 at 15:36
34
votes

I like Ctrl+M, Ctrl+M. To expand/collapse the current code block.

2
  • 2
    Seems like ctrl + m + m works as well. So you don't have to release the ctrl button after the first m. Dec 7, 2012 at 15:38
  • Every one of shortcuts is editable and the default often is that there is version with ctrl two times or the firts time.
    – Preza8
    Jul 30, 2013 at 9:41
34
votes

One that I use often but not many other people do is:

Shift + Alt + F10 then Enter

If you type in a class name like Collection<string> and do not have the proper namespace import then this shortcut combination will automatically insert the import (while the carret is immediately after the '>').

Update:

An equivalent shortcut from the comments on this answer (thanks asterite!):

Ctrl + .

Much more comfortable than my original recommendation.

5
  • This is for View.SHowSmartTag so any smart tag that appears will have their menu openw ith this (e.g., implement interface). I change this mapping to Alt+Down arrow. Sep 19, 2008 at 2:29
  • I tend to hit Windows button -> down -> right -> enter, which to me is faster than repositioning my hands in a weird way in order to press Shift+Alt+F10+Enter.
    – Rahul
    Sep 19, 2008 at 8:14
  • 12
    You can do Ctrl + "." for the same purpose, and it's much, much more comfortable.
    – asterite
    Oct 27, 2008 at 15:33
  • Yes, you can do Ctrl+".", but the original Shift + Alt + F10 will also work in other MS applications such as Outlook, PowerPoint, Excel and Word. Jan 21, 2009 at 23:15
  • -1 as dup of one above (even if this was first, not surte if it was) Jun 26, 2009 at 11:41
34
votes

Shift+ESC

This hides/closes any of the 'fake window' windows in Visual Studio. This includes things like the Solution Explorer, Object Browser, Output Window, Immediate window, Unit Test Windows etc. etc. and still applies whether they're pinned, floating, dockable or tabbed.

Shortcut into a window (e.g. Ctrl + Alt + L or Ctrl + Alt + I) do what you need to do, and Shift + Esc to get rid of it. If you don't get rid of it, the only way to give it focus again is to use the same keyboard shortcut (or the mouse, which is what we're trying to avoid....)

Once you get the hang of it, it's immensely useful.


Grrr....The amount of times of hit Ctrl + F4 to close the 'window' only to see my current code window close was insane before I found this, now it only happens occasionally..

4
  • This is awesome!!! (shift+esc) I always build, have the output window fly out and have the mouse cursor hovering, which prevents it from autohiding. This makes me move my hands off the keyboard, which I HATE. But thanks to this, you've solved my single biggest annoyance with visual studio. THANK YOU THANK YOU THANK YOU.
    – Tim Coker
    Jul 22, 2010 at 16:46
  • 1
    "If you don't get rid of it, the only way to give it focus again is to use the same keyboard shortcut" - Alt+F6 cycles through open tool windows, faster to press than Ctrl-W-stuff
    – user472875
    Dec 5, 2011 at 5:58
  • On MSVC 6.0 (or something even older?) [ESC] did the hiding (actually toggling IIRC) the output window. I have looked a long time for a replacement to that one, thanks!
    – Valmond
    Apr 21, 2012 at 17:43
  • VS 2012 use Ctrl+Shift+[ instead of Ctrl+Alt+L - which navigates to the current file instead of navigating to last selected file in Solution Explorer.
    – yzorg
    Jan 24, 2013 at 15:58
24
votes

My favorite: F12 (go to definition) and Shift+F12 (find references).

The latter is useful with F8 (go to next result).

Ctrl+- and Ctrl+Shift+- are mapped to my mouse's back and forwards buttons.

Ctrl+. is useful too, especially for adding event handlers and "using" statements.

1
  • I use <menu key>, <g> for go to definition. Its much easier to reach than F12. <menu key>, <a> will do find all references, too. Most of the time when I'm browsing code, I have my left hand on keyboard and my right hand on the mouse, which means I can right click and press <g> or <a> for these as well, which is pretty quick.
    – Tim Coker
    Jul 22, 2010 at 16:43
24
votes

Visual Studio 2005/2008 keybinding posters:

These don't cover customizations, but they're good reference materials and definitely helpful for finding new shortcuts.

Also, a macro that dumps all the current bindings to a HTML file:

http://www.codinghorror.com/blog/archives/000315.html

1
22
votes

Alt+Shift+arrow keys(,,,)

This allow you to select things in a block. Like you could select all of the "int" in the block and then search and replace to double for example.

**int** x = 1;
**int** y = 2;
**int** z = 3;
1
  • Hey, i'm pretty sure this is acutally CTRL not ALT in all of the above examples...
    – JTech
    Jun 21, 2012 at 11:03
19
votes

Ctrl+M, O. Can collapse and expand all sections of code in a particular file.

3
  • VS O8 link has been removed from the destination site. It says, due to possible copyright infringement. Oct 21, 2008 at 20:42
  • It's not Ctrl+M,0 but Ctrl+M,O (<- not zero but an O)
    – dance2die
    Mar 11, 2009 at 2:34
  • If you want to expand again use CTRL + M, P
    – n00b
    Dec 5, 2012 at 17:50
19
votes

Open and set focus in Solution Explorer: Ctrl+Alt+L

2
  • I usually hit "Esc" to get back. Dec 14, 2009 at 16:58
  • Also, for ReSharper users, Alt+Shift+L focuses on the current file in the Solution Explorer. May 23, 2013 at 21:28
18
votes

One that other editors should take up: Ctrl+C with nothing selected will copy the current line.

Most other editors will do nothing. After copying a line, pasting will place the line before the current one, even if you're in the middle of the line. Most other editors will start pasting from where you are, which is almost never what you want.

Duplicating a line is just: Hold Ctrl, press c, then v. (Ctrl+C, Ctrl+V)

2
  • 2
    This could also be annoying if you press Ctrl+C by mistake instead of Ctrl+V
    – shoosh
    Mar 10, 2009 at 23:49
  • And CodeRush adds even more w/ Ctrl W and auto stuff on Ctrl-C.... Jul 1, 2009 at 21:23
17
votes

CTRL+F5 (Start Without Debugging)

CTRL+SHIFT+B (Build Solution)

2
  • 6
    F7 is "build solution" for me.
    – korona
    Nov 7, 2008 at 8:39
  • How to build not the entire but the selected solution??
    – Narek
    Sep 11, 2012 at 6:18
14
votes

Here is a list that I use frequently:

Ctrl + I: for progressive search. If you don't type anything after I, and keep pressing I (holding the Ctrl key down), it will search the last item you had searched. Ctrl + Shift + I will reverse search. You might also want to use F3 (and Shift + F3) once some search string is entered.

Ctrl + K Ctrl + C: For commenting highlighted region. If nothing is highlighted, current line will be commented. Naturally, you can just hold Ctrl and press K, C in succession.

Ctrl + K Ctrl + U: For uncommenting highlighted region. Works like above.

Ctrl + /: Will take the cursor to the small search box on top. You can type ">of filename" (without the quotes) to open a file. Very useful if your project contains multiple files.

Ctrl + K Ctrl + K: Will bookmark the current line. This is useful if you want to look at some other part of code for a moment and come back to where you were.

Ctrl + K Ctrl + N: Will take you to the next bookmark, if there are more than one.

Ctrl + -: Will take the cursor to its previous location

Ctrl + Shift + -: Will take the cursor to its next location (if it exists)

Ctrl + Shift + B: Build your project

Ctrl + C: Although this does the usual copy, if nothing is highlighted, it copies the current line. Same for Ctrl + X (for cut)

Ctrl + Space: Autocomplete using IntelliSense

Ctrl + ]: Will take you to the matching brace. Works with all kinds of braces: '(', '{', '['. Useful for big blocks.

F12: Will take you to the function definition/variable definition.

Alt + P + P: Will open up project properties. Although not many use this, it useful if you want to quickly change the command line arguments to your program.

F5: To start debugging

Shift + F5: To stop debugging

While debugging, you can use Ctrl + Alt + Q to add a quick watch. Other debugging shortcuts can be found in the debug drop down menu.

0
13
votes

Ctrl+F10

run to cursor when debugging. Looked for this for ages before I found the keyboard shortcut...

12
votes

If 'Favorite' is measured by how often I use it, then:

F10 : Debug.StepOver

:)

12
votes

By usage, the pair:

  • Ctrl+Enter: insert blank line above the current line.
  • Ctrl+Shift+Enter: insert blank line below the current line.
3
  • CTRL + ENTER inserts above the current line on my VS2008.
    – Ash
    Jan 10, 2010 at 13:44
  • Oops, I had them backwards. :o I don't even think about it anymore. :) Jan 10, 2010 at 15:47
  • This is simple, but very useful. It could save a lot of keystrokes, thank you.
    – CMinus
    Feb 28, 2010 at 5:04
12
votes

When the IntelliSense drop down is displayed, holding down Ctrl turns the list semi-transparent so you can see what is hidden behind it :)

1
  • If only I knew this before, I would have saved myself so much time and reliance on the Esc key :)
    – munnster79
    Jul 19, 2012 at 11:44
11
votes

Ctrl+Alt+P -> Attach to process

11
votes

Haven't seen this one ...

Ctrl + Up

Ctrl + Down

Scrolls the window without moving the cursor.

1
  • It depends. On Visual Basic 2005 Express Edition (is a version of Visual Studio 2005 - 8.0.50727.42 (RTM 050727-4200)), it instead jumps to the previous/next subroutine (Sub or Function). It is still useful, though. Nov 27, 2012 at 13:00
1
2 3 4 5

Not the answer you're looking for? Browse other questions tagged or ask your own question.