61

Xcode underlines all occurrences of a symbol that the cursor is on. However, the underline doesn't exactly "pop out" in the source code. Is it possible to make Xcode highlight the background color of the symbol, like Eclipse does it? I can't find anything in the Preferences panel.

Xcode:

Xcode

Eclipse:

Eclipse

Micah Hainline
  • 14,367
  • 9
  • 52
  • 85
Tomas Andrle
  • 13,132
  • 15
  • 75
  • 92
  • Have you, by any chance, figured out the answer? – Blaz Apr 21 '12 at 10:24
  • @courteous Nope. But I hope that post-4.4 Xcode updates will bring some improvements in this area. – Tomas Andrle Apr 21 '12 at 10:59
  • 7
    Cmd+E, Cmd+F and Cmd+G combo is usefull. http://stackoverflow.com/questions/2439701/in-xcode-can-you-have-it-automatically-highlight-references-to-the-selected-obje –  Oct 02 '12 at 06:18
  • 4
    Depending on why you want to do this, edit all in scope (Ctrl-Cmd-E) may be helpful. – CuriousRabbit Oct 18 '12 at 02:18
  • @CuriousRabbit yes, that is the closest thing I have found. Thanks. – Tomas Andrle Oct 18 '12 at 07:03
  • @TomA Cmd+E Cmd+G combo is enough. – Míng Feb 21 '14 at 05:09
  • 1
    Be sure to look for (and vote up) Balazs Vadnai's answer below. It is the only CORRECT solution posted. – Alex Worden Mar 01 '16 at 18:19
  • As of Xcode 12 and the demise of Alcatraz, highlighting the symbol the cursor is on is subtle, but it does work. Note that double clicking on a symbol and selecting it will **not** highlight other instances, but _single clicking on a symbol to place the cursor inside it_ **will** highlight other instances of the symbol. – Robert Atkins Jun 09 '21 at 09:45

7 Answers7

20

XCode already has this feature but there's a delay on it after you single click on the text you want to highlight. You can set the delay to 0 seconds.

XCode > Preferences > TextEditing > HighlightInstancesOfSelected and set Delay to 0s

This works but I wasn't able to change the color of it. It is a pale blue color and a bit hard to see.

Vivian_S.O.
  • 217
  • 2
  • 2
10

Search for AutoHighlightSymbol in Alcatraz (Xcode's package manager). It will do exactly what you want.

After you have the plugin installed, select Editor > Edit Highlight Color. This is transparent by default, so you have to pick one that suits your color theme best.

EDIT: Now that Alcatraz is gone, you're going to have to install the plugin manually. Download from their GitHub, build the project and restart Xcode - which needs to be unsigned for being able to load 3rd party bundles. More info on this here.

Balazs Vadnai
  • 111
  • 1
  • 6
  • Thanks - I just installed AutoHightlightSymbol. It was very easy to install the Alcatraz Package Manager (which I had to Google to figure out what you were talking about). It's a little unintuitive that the default preferences are to not highlight the symbols but after reading the AutoHightlightSymbol github readme I have it working. THANK YOU! – Alex Worden Mar 01 '16 at 18:16
  • I wrongly thought that the package manager comes with Xcode, that's why I didn't explain it further. I have edited the answer, thanks! – Balazs Vadnai Mar 02 '16 at 15:28
  • 2
    This is the best plugin, since it relies on the "highlight selected symbol" feature of Xcode, so comments and so forth are ignored. – Binarian May 04 '16 at 08:35
3

This is not exactly what you are looking for, but you may want to check out the Polychromatic Xcode plugin (most easily installed via Alcatraz). It gives every symbol a unique color, which is used consistently throughout. So every instance of myVar might be blue, and every instance of myOtherVar might be red.

Zev Eisenberg
  • 8,080
  • 5
  • 38
  • 82
1

This plugin does what you want. It's available through Alcatraz:

https://github.com/keepyounger/HighlightSelectedString

Zev Eisenberg
  • 8,080
  • 5
  • 38
  • 82
  • 2
    Unfortunately not. What Xcode does with the underline is showing occurrences of this variable **in the current scope**. This plugin simply RegExes over the source and highlights everything with the same content. It's not half as useful. Mind that you have one scope per if, for example. This can't be handled by this plugin. – Julian F. Weinert Aug 19 '15 at 10:02
0

I don't know if this is still relevant, but when you hover with the cursor on a symbol a small selection menu shows up and you can select "Edit All in Scope". This highlights all such symbols in a much more visible way. As the name suggests, this functionality is meant for a higher purpose, but I think it comes in handy even just for highlighting. I don't know if this feature was available before Xcode 5.

Emerald Weapon
  • 2,392
  • 18
  • 29
  • 1
    Thanks. That's what Ctrl-Cmd-E does as @CuriousRabbit suggested, see comments below question. I now use this regularly when I need to highlight a symbol. – Tomas Andrle Jul 31 '14 at 11:08
  • Oh, didn't see that. Anyway, I also have been fighting this since forever... I hope future releases will provide such an obvious an useful feature. – Emerald Weapon Jul 31 '14 at 11:27
-1

community!

I have the same trouble and found something like that. (where the "currencyId" i select,another its work of plugin)

enter image description here

Its, i guess, do the same thing like [Cmd+E, Cmd+F and Cmd+G combo] But its easier,you must only select word in your code.

How to install it to Your XCode:

  1. Launch XCode
  2. On top menu select Window->Package Manager
  3. In search type "highlightSelectedString" enter image description here
  4. Install it!
  5. ?

  6. Profit

And also you can change color of highlighting!!!

  1. go to Edit->Set Highlight color

  2. Choose your color

Mr.Fingers
  • 1,105
  • 1
  • 11
  • 15
  • 1
    Unfortunately not. What Xcode does with the underline is showing occurrences of this variable **in the current scope**. This plugin simply RegExes over the source and highlights everything with the same content. It's not half as useful. Mind that you have one scope per if, for example. This can't be handled by this plugin. – Julian F. Weinert Aug 19 '15 at 10:02
-3

ok go to xcode select preferences pop over will come select fonts and colors down u can see 4 buttons,with 1 having name selection,click and choose any deep color

raj
  • 163
  • 1
  • 3