89

When I mark a word (of any kind) I would like all occurrences (in that particular file) of that word to be highlighted in the scrollbar on the right hand side.

This was a feature in VS2015 and VS2013. I cannot imagine that they removed it, I just don't know how to switch it on. None of the apparent possibilities in Tools -> Options (image) helps me. enter image description here

Ps. I am using Visual Studio 17 Professional. Thank you.

Richard
  • 106,783
  • 21
  • 203
  • 265
ToFo
  • 1,643
  • 1
  • 19
  • 34
  • 2
    This is now a new feature in Visual Studio 2022 17.4 (on by default), but it highlights both text in the editor and annotates the scrollbar. It can be toggled on or off using `Options | Text Editor | General | Show selection matches`. – Aaron Nov 18 '22 at 09:13

5 Answers5

162

This was a feature in VS15 and VS13.

Actually it was not.

It is a feature of the Productivity Power Tools extension. That extension is now just an installer for separate single feature extensions. I think you'll be wanting Match Margin.

For Visual Studio 2022 Match Margin is also available.

habakuk
  • 2,712
  • 2
  • 28
  • 47
Richard
  • 106,783
  • 21
  • 203
  • 265
  • 1
    I'm curious. I remember this feature being available on VS 2015, but I don't remember installing and extension for it. Was the Productivity Power Tools extension bundled with Visual Studio on former versions? – M Granja Mar 07 '18 at 15:07
  • @MGranja Some highlighting was included in the box, but not for find ((IRC definition/reference highlight was included, which would often appear similar). – Richard Mar 07 '18 at 15:18
  • Yeah, that would explain it then. And them removing it from vanilla VS confused some people, like me. – M Granja Mar 15 '18 at 13:37
  • 1
    @MGranja Visual Studio code has this feature built-in, maybe that's what you were thinking of? – jrh Oct 07 '19 at 14:16
  • 3
    Also just as a heads up, the default color scheme for Match Margin picks a rather subtle color, when I first loaded it I thought it wasn't working, but it turns out that it picked a color I could barely see, and it drew a very small bar because the file was large. You can change the color by going to Tools -> Options -> Environment -> Fonts and Colors -> Match Color. The color it chooses to show in the scroll bar is the *foreground* (text) color, not the *background color*. – jrh Oct 07 '19 at 14:21
  • 2
    Another thing, it matches text, it's not necessarily language aware. E.g., if you have 8 functions with a local variable or parameter named `name`, and you click on `name`, it will highlight every instance of `name` in the file even though it isn't the same variable. Probably best to use this as a quick examination tool for global variables and fields. It's funny because the default identifier highlight system (that doesn't draw to the scroll bar) *is* language aware and will only highlight variables that are in the proper scope. – jrh Oct 07 '19 at 14:25
  • @jrh No, I almost never use VS code. I think Richard's suggestion is more likely. – M Granja Nov 28 '19 at 19:12
18

Right now, the only way I know (without installing new extensions) is to select (double click) the word and hit ctrl-f (find). Scroll map should highlight all occurences (mine are orange)

15

There's another extension which does exactly this, with options to customize colors and more. it called Word Highlight With Margin.

The extension created by Trung Kien Phan

Screenshots

VS2017/VS2019/2022 Version

Download link from Visual Studio market place - VS2017, VS2019, VS2022

Previous versions:

VS2015

VS2010, VS2012, VS2013

itsho
  • 4,640
  • 3
  • 46
  • 68
1

The setting is in "Options > Text Editor > C# > Advanced" and is called "Highlight references to symbol under cursor": enter image description here

This is using Visual Studio 2019, version 16.1.25.

William
  • 3,335
  • 9
  • 42
  • 74
0

MultiWordHighlight can highlight different words with different color

https://github.com/jendelel/MultiWordHighlight

update

  1. How to install

    Install via Visual Studio Marketplace (https://marketplace.visualstudio.com/items?itemName=jendelel.MultiWordHighlight).

  2. How to use

    Right click on any word under the caret and select Toggle highlight of current word in the MultiWordHighlight menu.

camino
  • 10,085
  • 20
  • 64
  • 115