How to get Visual Studio 2010 to highlight instances of a variable
Asked Answered
B

10

32

I'm new using vs2010 I've read that when you click on a variable its suppose to highlight all the instances of that variable in that file and highlight red or show an error as well where the number line is located. How can I get vs2010 to do this because by default it doesn't do that for me and it would be great for the highlighting to work. Thanks.

Bartram answered 24/2, 2012 at 17:58 Comment(3)
What language are you coding in?Ez
General for all supported languages.Bartram
This is not a "general" feature, that's why I asked. It's supported in C# and VB.NET, but not in the C++ IDE.Ez
L
29

The Highlight all occurrences of selected word extension in Visual Studio Gallery does just that.

Highlight all occurrences of selected word

Leda answered 24/2, 2012 at 19:11 Comment(6)
is there an way to have it highlight multiple variables using different colors for each variable?Roccoroch
RayLoveless, there's an extension called StickyHighlight, it does just that: visualstudiogallery.msdn.microsoft.com/…Stormystorting
I have performance issues with this extension. If selecting a common variable (e.g. "i") which is used everywhere in a large file, VS freezes while plugin is working, which can be several seconds.Ozone
New version of this extension.Alexi
is there a way to edit all of the strings that were highlighted at the same time?Prolepsis
but can not install this version on VS 2017 use this version : marketplace.visualstudio.com/…Cousingerman
A
29

Productivity Power Tools for 2010 in the Visual Studio Gallery can do this, it took me a bit to find out how I did it, but in the Tools->Options... menu, there is a "Productivity Power Tools' drop down.

The default for the 'Words matching the caret location color in the editor' is fully transparent, so it isn't used. A color choice dialog pops up and you can set the color. Just ensure you set an alpha value above 1 to enable it.

The color values I used below are [153, 138, 188, 219] It seems to work well in light themes.Productivity Power Tools->Enhanced Scroll Bar

Accomplishment answered 4/11, 2013 at 23:27 Comment(2)
+1 exactly what i was looking for so long: possibility to customize color for matching entries. thx!Jeramey
Updated Link for 2015 Visual studio : marketplace.visualstudio.com/…Catnap
S
13

On the Tools menu, click Options.

In the Options dialog box, expand Text Editor , and then complete one of the following tasks:

  • For Visual Basic, expand Basic, click VB Specific, and then select or clear Enable highlighting of references and keywords.
  • For C#, expand C#, click Advanced, and then select or clear Highlight references to symbol under cursor.

From: msdn

Strepitous answered 24/2, 2012 at 18:25 Comment(2)
Thanks, but I was hoping to that there was feature in maybe text editor for all languages in General. Like Jim Fell mentioned with Notepad++.Bartram
I've Productivity Power Tools to highlight words much more quickly than this native VS option.Pyroligneous
D
8

In visual Studio 2012, Tools -> Options -> Environment -> Fonts and Colors -> [Text Editor] [Display Itemns] -> Highlighted References -> Item background: Choose the color you want.

Dissipate answered 11/3, 2014 at 21:35 Comment(1)
In VS2017, suddenly, the Highlighting wasn't working anymore. In the end it came down to the highlight color being set to the same color as the normal background color -_-. I did NOT change it manually, so no idea why it was suddenly messed up.Pale
D
3

Options -> Environment -> Fonts and Colors -> Highlighted Reference then change foreground and background colors of your choice.

Doenitz answered 3/10, 2014 at 14:6 Comment(0)
G
1

in vs 2012: Tools > Options > Env > Fonts and Colors > Text Editor > Highlighted Reference

Gifferd answered 18/4, 2017 at 7:19 Comment(0)
N
0

In case someone else bumps into this, much like I did looking for the same thing, Visual Studio Express editions don't support extensions, which means no selection highlighting in C++. More importantly, if you get an error trying to install an extension, don't worry, or rather, worry for other reasons, it's normal.

nuGet in 2012 is the only exception I've bumped into, but personally I (and I know many like me) have to use 2010.

Niggling answered 17/6, 2013 at 11:26 Comment(0)
C
0

I came here from google while looking to do the same thing with Visual Studio 2017 community edition. The answers above point out you can turn this on for VB and C#. The option does not exist for C or C++. ie. for C/C++ the option does not exist in advanced settings so you can not right click the variable and select highlight variable.

However, I learned its simpler for C/C++ to get the equivalent behaviour. Simply double click the variable/function to select it. The editor will highlight all instances of the variable or function in the file. Its not limited by blocks. Its highlighted in the entire file.

Caudillo answered 20/6, 2017 at 12:52 Comment(0)
M
-3

If you are using VS2013 the following extension would solve this

https://visualstudiogallery.msdn.microsoft.com/df093e9f-3e74-41c5-aeec-6371436423c5

Mordancy answered 6/8, 2015 at 10:4 Comment(0)
M
-4

I think you mean placing a cursor over the line and then pressing F9. This will make the code stop there. Place the mouse cursor over the desired string value and it will pop up....that's the lazy way I do it..:-)

Margaritamargarite answered 24/2, 2012 at 18:3 Comment(1)
That's the code break, great tip! But I was looking for maybe a some option that was not set by default to highlight the instances of a variable. But thanks.Bartram

© 2022 - 2024 — McMap. All rights reserved.