182
votes

Visual Studio is such a massively big product that even after years of working with it I sometimes stumble upon a new/better way to do things or things I didn't even know were possible.

For instance-

  • Crtl + R, Ctrl + W to show white spaces. Essential for editing Python build scripts.

  • Under "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\Text Editor" Create a String called Guides with the value "RGB(255,0,0), 80" to have a red line at column 80 in the text editor.

What other hidden features have you stumbled upon?

1
  • thanks. actually, I stumbled at "show white spaces" by accident, and wanted to get rid of it. thanks a lot! Jan 31, 2012 at 16:12

100 Answers 100

123
votes

Make a selection with ALT pressed - selects a square of text instead of whole lines.

11
  • 9
    Ctrl-Alt will select whole words. Alt will change the size of the selection area by one character at a time.
    – firedfly
    Oct 15, 2008 at 13:47
  • 4
    This works in MS Word and OO Writer as well. I've used it a lot.
    – Bård
    Aug 27, 2009 at 7:17
  • 3
    This (called "block select") also works with the keyboard- hold alt+shift then use the arrow keys.
    – arolson101
    Oct 16, 2009 at 16:42
  • 1
    In addition, if you select an empty horizontal column this way, anything you type will get duplicated on every line, behaving like a huge cursor :) May 20, 2010 at 13:32
  • 1
    I saw this being sold as a feature for VS 2010, but I just tried it in VS 2008 and it worked. I'm flabbergasted. this is amazingly usefull!
    – DaveDev
    Sep 5, 2010 at 22:58
95
votes

Tracepoints!

Put a breakpoint on a line of code. Bring up the Breakpoints Window and right click on the new breakpoint. Select 'When Hit...'. By ticking the 'Print a message' check box Visual Studio will print out a message to the Debug Output every time the line of code is executed, rather than (or as well as) breaking on it. You can also get it to execute a macro as it passes the line.

2
  • 1
    I know I'm late to the game, but that's a great feature I never knew about!
    – Jerry
    Aug 25, 2009 at 19:37
  • 7
    For extra points you can make a local variable asignment in the when hit button. { localVariable = 1.0f } or increase values by { staticVariable += 0.1f } May 10, 2010 at 14:28
91
votes

You can drag code to the ToolBox. Try it!

5
  • Holy crap so you can! (Thanks!)
    – Ali Parr
    Feb 4, 2009 at 17:57
  • doesn't seem to be much use over snippets though
    – jk.
    Dec 7, 2009 at 12:45
  • 33
    Dear God...it's a whole new level of copy-and-paste. Copy-and-paste-paste-paste. I know a lot of programmers who I hope never find out that you can do this.
    – Ryan Lundy
    Mar 23, 2010 at 20:34
  • It would be cool if you could tell it to eval the code when you clicked the button, like a bookmarklet.
    – intuited
    Aug 8, 2010 at 7:35
  • oh no. What is this bastardize function doing!
    – user34537
    Dec 5, 2010 at 5:35
79
votes

Click an identifier (class name, variable, etc) then hit F12 for "Go To Definition". I'm always amazed how many people I watch code use the slower right-click -> "Go To Definition" method.

EDIT: Then you can use Ctrl+- to jump back to where you were.

8
  • 8
    And don't forget Ctrl+Shift+- [control shift minus] to jump forward! Jun 19, 2009 at 3:34
  • 5
    And Shift F12 for Find all references
    – Benjol
    Sep 2, 2009 at 6:35
  • 2
    You can also use ALT+left arrow to go back to where you were
    – arolson101
    Oct 16, 2009 at 16:43
  • 1
    With VB key settings, Shift-F2 also does a Go To Definition.
    – Ryan Lundy
    Dec 3, 2009 at 18:54
  • 1
    Might as well right-click-G if you're going the mouse route in the first place.
    – tsilb
    Jan 30, 2010 at 16:27
57
votes

CTRL+SHIFT+V will cycle through your clipboard, Visual Studio keeps a history of copies.

1
  • this can be found in edit.cycleclipboardring in keyboard mappings (in visual c++ this is Ctrl-Shift-Insert, not Ctrl-Shift-V)
    – default
    Jun 20, 2010 at 12:20
52
votes

Sara Ford covers lots of lovely tips: http://blogs.msdn.com/saraford/archive/tags/Visual+Studio+2008+Tip+of+the+Day/default.aspx

But some of my favourites are Code Snippets, Ctrl + . to add a using <Namespace> or generate a method stub. I can't live without that.

Check out a great list in the Visual Studio 2008 C# Keybinding poster: http://www.microsoft.com/downloadS/details.aspx?familyid=E5F902A8-5BB5-4CC6-907E-472809749973&displaylang=en

8
  • 1
    Sara Ford is the goddess of Visual Studio. I couldn't recommend her enough. Sep 19, 2008 at 8:27
  • Totally agree which I why I share her work. I'm really loving her current series which covers debugging Sep 20, 2008 at 10:21
  • Sad that she quit doing the tip of the day, though it's been so long since she worked with the innards of VS that it's completely understandable that she needed to move on...
    – Knobloch
    Feb 12, 2009 at 13:25
  • Thank you for mentioning CTRL+. I was searching for this one exactly. Aug 7, 2009 at 10:56
  • I was always using CTRL+ALT+F10. Didn't know CTRL+. does the same thing - thanks. Much more comfortable.
    – Noam Gal
    Aug 12, 2009 at 10:48
49
votes
CTRL-K, CTRL-D

Reformat Document!
This is under the VB keybindings, not sure about C#

2
  • 3
    yes, works under C#, Web Designer, XML editor, CSS editor, XSD editor, JavaScript (to an extent). Most of the supported file types Sep 19, 2008 at 8:19
  • Ctrl+K, Ctrl+F also formats whatever text you have selected (in C#, not sure about others). Jan 31, 2012 at 22:19
43
votes

How many times do you debug an array in a quickwatch or a watch window and only have visual studio show you the first element? Add ",N" to the end of the definition to make studio show you the next N items as well. IE "this->m_myArray" becomes "this->m_array,5".

0
41
votes

Incremental search: While having a source document open hit (CTRL + I) and type the word you are searching for you can hit (CTRL + I) again to see words matching your input.

3
  • 4
    It's called ">i<ncremental search".
    – Constantin
    Oct 7, 2008 at 20:33
  • As opposed to >ex<cremental search, which is what Firefox implements.
    – kibibu
    Jun 4, 2010 at 3:00
  • Coming from the Emacs world, this the first feature I looked for. :)
    – JesperE
    Mar 16, 2011 at 12:43
37
votes

You can use the following codes in the watch window.

@err - display last error
@err,hr - display last error as an HRESULT
@exception - display current exception
0
35
votes
  • Ctrl-K, Ctrl-C to comment a block of text with // at the start
  • Ctrl-K, Ctrl-U to uncomment a block of text with // at the start

Can't live without it! :)

10
  • Also true in VB.NET, except with ' rather than //
    – ChrisA
    Feb 8, 2009 at 9:10
  • Also true in SQL Server Management Studio, except using the SQL comment escape sequence of '--' Feb 9, 2009 at 17:11
  • 3
    I always wished you could toggle comments? Why would you want to "double comment" something? Surely pressing it again should un-comment...
    – Dan Diplo
    Aug 5, 2009 at 22:22
  • 16
    Sometimes you want to comment the entire function, and some lines inside are already commented (i.e. they are proper comments). In such cases it's not obvious what to do if you have a toggle, so it's generally better to make the decision explicit. Aug 13, 2009 at 8:46
  • 1
    Note that if you start at the beginning of text rather then beginning of line you will get the /* */ instead of //. This is by the way my most used feature
    – default
    May 18, 2010 at 18:39
25
votes

Stopping the debugger from stepping into trivial functions.

When you’re stepping through code in the debugger, you can spend a lot of time stepping in and out of functions you’re not particularly interested in, with names such as GetID(), or std::vector<>(), to pick a C++ example. You can use the registry to make the debugger ignore these.

For Visual Studio 2005, you have to go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio \8.0\NativeDE\StepOver and add string values containing regular expressions for each function or set of functions you wish to exclude; e.g.

std::vector.*::.*
TextBox::GetID

You can also override these for individual exceptions. For instance, suppose you did want to step into the vector class’s destructor:

std::vector.*::\~.*=StepInto

You can find details for other versions of Visual Studio at http://blogs.msdn.com/andypennell/archive/2004/02/06/69004.aspx

1
  • Wow, this is awesome. I had no idea this was possible. Aug 31, 2009 at 5:13
23
votes

Ctrl-F10: run to cursor during debugging. Took me ages to find this, and I use it all the time;

Ctrl-E, Ctrl-D: apply standard formatting (which you can define).

1
  • 1
    Ctrl+Shift+F10 to skip all code and run to the cursor. Nifty when trying to test specific lines of code. Jan 5, 2012 at 10:10
23
votes

TAB key feature.

  1. If you know snippet key name, write and click double Tab. for example: Write

    foreach

and then click tab key twice to

foreach (object var in collection_to_loop)
{

}

2. If you write any event, write here

        Button btn = new Button();
        btn.Click +=         

and then click tab key twice to

private void Form1_Load(object sender, EventArgs e)
{
        Button btn = new Button();
        btn.Click += new EventHandler(btn_Click);     
}    
void btn_Click(object sender, EventArgs e)
{
        throw new Exception("The method or operation is not implemented.");
}

btn_Click function write automatically

  1. in XAML Editor, Write any event. for example:

MouseLeftButtonDown then click tab
MouseLeftButtonDown="" then click tab again MouseLeftButtonDown="Button_MouseLeftButtonDown" in the code section Button_MouseLeftButtonDown method created.

0
21
votes

Sara Ford has this market cornered.

http://blogs.msdn.com/saraford/default.aspx

More Visual Studio tips and tricks than you can shake a stick at.

Some others:

  • The Visual Studio 2005 and 2008 3-month trial editions are fully-functional, and can be used indefinitely (forever) by setting the system clock back prior to opening VS. Then, when VS is opened, set the system clock forward again so your datetimes aren't screwed up.
  • But that's really piracy and I can't recommend it, especially when anybody with a .edu address can get a fully-functional Pro version of VS2008 through Microsoft Dreamspark.
  • You can use Visual Studio to open 3rd-party executables, and browse embedded resources (dialogs, string tables, images, etc) stored within.
  • Debugging visualizers are not exactly a "hidden" feature but they are somewhat neglected, and super-useful, since in addition to using the provided visualizers you can roll your own for specific data sets.
  • Debugger's "Set Instruction Pointer" or "Set Next Statement" command.
  • Conditional breakpoints (as KiwiBastard noted).
  • You can use Quickwatch etc. to evaluate not only the value of a variable, but runtime expressions around that variable.
2
  • 3
    If it's really piracy (which I agree with you about), then why would you even mention it?
    – Ryan Lundy
    Dec 3, 2009 at 18:56
  • 1
    Kyralessa, because some people probably don't care. However, with the Express editions being free I doubt there is an actual reason nowadays to use a pirated VS version.
    – Joey
    Sep 9, 2011 at 9:33
21
votes

T4 (Text Template Transformation Toolkit). T4 is a code generator built right into Visual Studio

1
  • Note: Not the Express Editions. (Still a great tip though.) Aug 31, 2009 at 5:21
17
votes

Custom IntelliSense dropdown height, for example displaying 50 items instead of the default which is IMO ridiculously small (8).

(To do that, just resize the dropdown next time you see it, and Visual Studio will remember the size you selected next time it opens a dropdown.)

2
  • 4
    You can't resize it anymore in VS2010, it bug me to no end.
    – manixrock
    Jun 11, 2010 at 15:10
  • in Vs2008 I'm able to change the width but not the height .
    – Kapil
    Sep 19, 2010 at 17:15
16
votes

Discovered today:

Ctrl + .

Brings up the context menu for refactoring (then one that's accessible via the underlined last letter of a class/method/property you've just renamed - mouse over for menu or "Ctrl" + ".")

2
  • Alt+Shift+F10 does this as well (using C# keybindings) Nov 1, 2008 at 20:17
  • 4
    Much better than trying to hunt the tiny mouse click target in this situation
    – Richard Ev
    Dec 2, 2008 at 9:56
14
votes

A lot of people don't know or use the debugger to it's fullest - I.E. just use it to stop code, but right click on the red circle and there are a lot more options such as break on condition, run code on break.

Also you can change variable values at runtime using the debugger which is a great feature - saves rerunning code to fix a silly logic error etc.

13
votes

Line transpose, Shift-Alt-T
Swaps two line (current and next) and moves cursor to the next line. I'm lovin it. I've even written a macro which changed again position by one line, executed line transpose and changed line position again so it all looking like I swapping current line with previous (Reverse line transpose).

Word transpose, Shift-Ctrl-T

3
  • This makes the line move down the page, how do you make a line move UP the page? Sep 17, 2009 at 19:54
  • GordonG, I've written following macro: Sub ReverseLineTranspose() DTE.ActiveDocument.Selection.LineUp DTE.ExecuteCommand ("Edit.LineTranspose") DTE.ActiveDocument.Selection.LineUp End Sub
    – okutane
    Sep 26, 2009 at 3:23
  • 1
    Could do with it here as it turns out :)
    – Benjol
    Nov 19, 2009 at 15:34
11
votes

When developing C++, Ctrl-F7 compiles the current file only.

11
votes

Document Outline in the FormsDesigner (CTRL + ALT + T)

Fast control renaming, ordering and more!

1
  • I can't believe I didn't know about this. My life is changed. Oct 7, 2010 at 15:05
11
votes

To auto-sync current file with Solution Explorer. So don't have to look where the file lives in the project structure

Tools -> Options -> Projects and Solutions -> "Track Active Item in Solution Explorer"

Edit: If this gets too annoying for you then you can use Dan Vanderboom's macro to invoke this feature on demand through a keystroke.

(Note: Taken from the comment below by Jerry).

4
  • 3
    this gets annoying after a while. i wish there were a keyboard shortcut to do this on demand.
    – kenwarner
    Jul 28, 2009 at 14:14
  • 2
    Here's a post on how to track on demand. dvanderboom.wordpress.com/2008/03/21/…
    – Jerry
    Aug 25, 2009 at 19:44
  • If you have lots of files open, it can kill VS (without warning) if you do things like 'Close all but this' (from PowerCommands, I think).
    – Benjol
    Sep 2, 2009 at 6:39
  • Resharper makes the need for this redundant as you can do Shift+Alt+L to jump directly to the current file in the Solution Explorer; or Ctrl+Shift+N to keyword search for any file in the Solution.
    – cbp
    Jul 9, 2010 at 8:24
9
votes

I'm not sure if it's "hidden", but not many people know about it -- pseudoregisters. Comes very handy when debugging, I've @ERR, hr in my watch window all the time.

3
  • 1
    I've heard @xxx is being phased out in favor of $xxx. FWIW, WinDbg also uses $xxx form.
    – Constantin
    Oct 7, 2008 at 20:32
  • Can't you just do "hr,hr" in a watch window? I've used that all the way back in VC6...
    – LarryF
    Dec 11, 2008 at 22:52
  • Excellent. As the linked article suggests, setting conditional breakpoints on @TIB will drastically simplify the debugging of multithreaded apps. Aug 31, 2009 at 5:17
9
votes

Ctrl-Minus, Ctrl-Plus, navigates back and forward where you've been recently (only open files, though).

2
  • Yep, LOVE these- use them everyday.
    – MaseBase
    Nov 20, 2008 at 0:58
  • Very useful if you hit F+12 to go to a definition and then want to go back to where you were. May 19, 2010 at 10:18
9
votes

I don't use it often, but I do love:

ctrl-alt + mouse select

To select in a rectangular block, to 'block' boundaries.

As noted in comments,

alt + mouse select

Does just a plain rectangular block.

6
  • 4
    A downvote is amusing, given that this is a valid action in VS :) Good luck to you though, mysterious hater.
    – Noon Silk
    Aug 31, 2009 at 4:49
  • 2
    Maybe it's a bit early, but reading this made me want to try it on Firefox. Turns out, ctrl-alt-shift allows you to use the mouse to drag the entire document across the screen, similar to how a PDF document works.
    – KdgDev
    Aug 31, 2009 at 5:42
  • How does it differ from alt + mouse select?
    – Guffa
    Aug 31, 2009 at 5:49
  • Guffa: It goes to block-endings only. alt-select lets you choose any area containing anything. They are different.
    – Noon Silk
    Aug 31, 2009 at 6:12
  • Though I do think it can just be 'ctrl-alt', not 'shift' as well.
    – Noon Silk
    Aug 31, 2009 at 6:20
9
votes

Here's something I learned (for C#):

You can move the cursor to the opening curly brace from the closing curly brace by pressing Control + ].

I learned this on an SO topic that's a dupe of this one:

“Hidden Secrets” of the Visual Studio .NET debugger?

0
8
votes

CTRL + Shift + U -> Uppercase highlighted section. CTRL + U -> Lowercase the highlighted section Great for getting my SQL Statements looking just right when putting them into string queries.

Also useful for code you've found online where EVERYTHING IS IN CAPS.

1
  • 2
    Too bad they don't have a CamelCase CTRL+Shift option... :) That's probably my #1 refactor I do when I take over a project... Larry
    – LarryF
    Dec 15, 2008 at 23:31
8
votes

Middle Mouse Button Click on the editor tab closes the tab.

1
  • 1
    I use this all the time when I'm coding because I'm looking up code and then closing it (the "X" for closing is rather far). Nov 12, 2009 at 15:18
8
votes

To display any chunk of data as an n-byte "array", use the following syntax in Visual Studio's QuickWatch window:

variable, n

For example, to view a variable named foo as a 256-byte array, enter the following expression in the QuickWatch window:

foo, 256

This is particularly useful when viewing strings that aren't null-terminated or data that's only accessible via a pointer. You can use Visual Studio's Memory window to achieve a similar result, but using the QuickWatch window is often more convenient for a quick check.

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