289

Eclipse does not highlight matching variables for me:

enter image description here

I've already tried to change "Mark occurrences" via

Window -> Preferences -> Java -> Editor -> Mark Occurrences

but it didn't work. I am not sure why this is not working while others have been able to fix the problem.

Can anyone tell me how can I set highlighting matching variables?

Looking for same variables with my eyes really bothering me too much.

Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
Seho Lee
  • 4,048
  • 9
  • 32
  • 42
  • 7
    I had this happen just now even though "Mark Occurrences" was already checked. I thought to myself "Come on we are talking Eclipse here...". To fix it, I unchecked then clicked `Apply`. I then checked it again and clicked `Apply` followed by `OK` – Someone Somewhere Dec 03 '13 at 06:21
  • possible duplicate of [Eclipse problem - doesn't highlight references anymore](http://stackoverflow.com/questions/919614/eclipse-problem-doesnt-highlight-references-anymore) – brandizzi Mar 26 '14 at 12:51
  • after doing what the accepted answer says, you might have to restart eclipse. – mathheadinclouds Jan 11 '15 at 10:33
  • 1
    This actually solved my problem xD – Alex Vargas Jul 26 '18 at 17:19
  • 3
    ALT + SHIFT + O Try turning int on/off. – Vaibs Apr 07 '20 at 14:59

18 Answers18

500

Try:

window > preferences > java > editor > mark occurrences 

Select all options available there.

Also go to:

Preferences > General > Editors > Text Editors > Annotations

Compare the settings for 'Occurrences' and 'Write Occurrences'

Make sure that you don't have the 'Text as higlighted' option checked for one of them.

This should fix it.

Korhan Ozturk
  • 11,148
  • 6
  • 36
  • 49
  • 7
    I selected all options but this eclipse still not highlighting variables. – Seho Lee Mar 29 '12 at 06:36
  • http://www.eclipse.org/forums/index.php/mv/tree/57656/#page_top according to link, it appears that mark writing occurences in jsp has been disabled due to deadlock bug. I am making jsp file on web dynamic module 3.6 so I guess that was the cause. It seems everything going to be fine if I set my web dynamic module 3.6 to 4.0. Anyways, I am very thankful for your answer. – Seho Lee Mar 30 '12 at 04:54
  • 5
    Thanks! In eclipse Juno (under ubuntu 12.04) the settings did not start working until I restarted eclipse. – arun Jun 13 '13 at 15:50
  • 1
    If still doesn't work, workaround: switch to Outline view, select something and then switch back to your editor. – M. Usman Khan Feb 18 '14 at 12:45
  • For those using Titanium Studio on a Mac (built on Eclipse), you'll want `Preferences > Studio > Editors > JavaScript > Mark occurrences...`. – adamdport Apr 18 '14 at 16:14
  • Thanks! Turns out it *was* working for me, but after I switched the Monokai theme it still had black as the highlighting color. Not visible in a Dark theme! – apraetor Nov 21 '17 at 16:09
  • it still was set as desired but didnt work, so i changed occurences and write occurence (unchecked "as text" option) and then changend the same setting back as before. Now it works (Eclipse oxygen3.x). – Kaspatoo May 16 '18 at 11:35
  • For me with eclipse oxygen, Above method didnt work. I had to go to `Mark Occurrences` in `Java editor preferences` and select `Mark occurrences of current element` chceckbox. – instinct May 31 '18 at 11:00
  • This worked for Eclipse 2019-09 R (4.13.0). Updates were run and a restart occurred, for some reason java > editor > mark occurrences was disabled after this. I re-enabled it which solved the problem. – Navigatron Dec 05 '19 at 10:36
  • This worked for Spring Tool Suite 4 Version: 4.5.0.RELEASE. Thanks – Vishal Patel Jan 22 '20 at 10:31
  • For me, I had an "unbound" in the build path. Once this was fixed, everything worked well. More info in one of the solution towards the bottom that mentions "project build path" – h8MyJob Jun 22 '23 at 21:24
61

Alt + Shift + o
Will solve your problem and agree with @Korhan Ozturk as well :)

This is known as Toggle Mark occurrence (Alt + Shift + O), Means will highlight all occurrence of focused variable. Same thing can be achieved from tool bar as follows

enter image description here

In same tool bar there is another switch if you turn that on you will see complete path for opened file, That is Breadcrumb enter image description here

there are some more very useful switches like word wrap, Show white Characters just after toggle mark occurrence

Vinay Sharma
  • 1,163
  • 1
  • 10
  • 20
25

There is a bug in Eclipse Juno (and probably others) but I have a workaround!

If you have already checked all the configurations mentioned in the top answers here and it's STILL not working try this.

To confirm the problem:

  1. Select a variable
  2. Notice the highlight didn't work
  3. Click away from eclipse so the editor loses focus.
  4. Click on eclipse's title bar so it regains focus, your variable should be highlighted.

If this is happening for you, you must close ALL of your open files and reopen them. This bug seems to also make weird things happen with Ctrl+S saving of an individual file. My guess is that something is happening whereby internally eclipse believes a certain file has focus but it actually doesn't, and the UI's state is rendered as though a different file is being edited.

Edit: If it's STILL not working, you might need to restart eclipse, but if you don't want to, try selecting the item you want to see occurrences of then disable and re-enable the Mark Occurences Toggle button.

Which looks like this

Emperorlou
  • 800
  • 7
  • 11
  • I am using Eclipse Neon.3 and having this issue. This answer worked. What finally worked was to close all open files. I had a lot of open files. – Marquez Aug 24 '17 at 23:36
7

The only that worked for me was:

Java > Editor > Mark Occurrences:
Check "Mark occurrences of te selected element in the current file."
... and maybe all the ones below.
Rudolf Real
  • 1,948
  • 23
  • 27
5

Using Alt + Shift + o It works for me!

Gim
  • 79
  • 1
  • 4
3

For others running into this without any of the above solutions working AND you have modified the default theme, you might want to check the highlight color for occurrences.

Preferences > General > Editors > Text Editors > Annotations

Then select Occurrences in the Annotation Types, and change the Color Box to something other than your background color in your editor. You can also change the Highlight to a outline box by Checking "Text as" and selecting "Box" from the drop-down box (which is easier to see various syntax colors then with the highlights)

JReader
  • 320
  • 2
  • 9
3

I wish I could have read the response by @Ján Lazár.

In addition to all the configurations mentioned in the accepted answer, below setting solved my misery:

For large files the scalability mode must be turned off. Enabling scalability mode will disable reference highlighting.

enter image description here

PS: @Rob Hruska It would be great if this point is added in the accepted answer. Most of the readers do not bother to read the last response.

dsingh
  • 270
  • 1
  • 5
  • 17
2

For PHP you can set

window > preferences > PHP > editor > mark occurrences 

Please check first checkbox (Mark occurrences of selected element in the current file)


And also check

Preferences > General > Editors > Text Editors > Annotations

'Occurrences' and 'Write Occurrences' with different style and color

Devang Bhagdev
  • 633
  • 2
  • 8
  • 14
2

If highlighting is not working for large files, scalability mode has to be off. Properties / (c/c++) / Editor / Scalability

Ján Lazár
  • 491
  • 5
  • 8
2

Java - Editor - Mark Occurrences in Eclipse Photon.

Java - Editor - Mark Occurrences

Eclipse Java EE IDE for Web Developers. Version: Photon Release (4.8.0)

Ritesh
  • 7,472
  • 2
  • 39
  • 43
1

I just unchecked all, applied, checked all again, applied and it worked :) hopefully helps others.

jp093121
  • 1,752
  • 19
  • 13
1

Eclipse Toolbar > Windows > Preferences > General (Right side) > Editors (Right side) > Text Editors (Right side) > Annotations (Right side)

For Occurrences and Write Occurrences, make sure you DO have the 'Text as highlighted' option checked for all of them. See screenshot below:

enter image description here

enter image description here

enter image description here

Gene
  • 10,819
  • 1
  • 66
  • 58
1

maybe because it not supports code highlights inside scriplets. not sure though.

You can try using one of the eclipse plugin like 'glance search' which works great. Here's a link for that- http://code.google.com/p/eclipse-glance/

Kshitij
  • 8,474
  • 2
  • 26
  • 34
  • 1
    'Glance search' is basically a string highlighter which highlights all matching string/regex. It works on all view tabs and not just editors, so that means on your console/project explorer tab also. Press Ctrl+Alt+F to activate it – Kshitij Mar 29 '12 at 06:37
0

Sometimes problems in your project build path can cause this, make sure you resolve it first, in my case the prolem was :

enter image description here

And when fix it highlights come back.

Adil
  • 4,503
  • 10
  • 46
  • 63
  • 1
    It's interesting that this comment got -1 when it's actually the one that helped me. I was having this exact build path issue (different java version). Once i fixed it, highlighting came back. Link to fix unbound issue (https://sites.miis.edu/dreadkingrathalos/2017/06/05/unbound-classpath-container-jre-system-library-resolved/) – h8MyJob Jun 22 '23 at 21:15
0

I was having the same issue and the "make occurrences" and "annotations" solutions above did not help. If you are using Maven, I had to convert the project to a Maven project (right click on it in the Package Explorer and go down to configure), then build the project. Then the syntax coloring and highlighting worked correctly.

D. Smith
  • 739
  • 5
  • 9
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](http://stackoverflow.com/questions/ask). You can also [add a bounty](http://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question once you have enough [reputation](http://stackoverflow.com/help/whats-reputation). - [From Review](/review/low-quality-posts/11903951) – James Taylor Apr 05 '16 at 19:46
  • 1
    @JamesTaylor: This actually is an answer to the question, at least for the case where the OP was using maven, which appears to be unspecified. – gariepy Apr 05 '16 at 22:12
0

This is what worked for me (credit to YardenST from another thread): Instead of double clicking file when opening, right click on file -> Open with -> Java editor

Screenshot

Community
  • 1
  • 1
jericho
  • 9
  • 3
0

In Scala IDE click on this button in the toolbox to activate Mark Occurrences (off by default).

link to the screenshot

-1

I had this issue with Eclipse Mars for PHP developers, 64 bit edition for Windows. I now discovered that highlighting works out-of-the-box with the 32 bit version. Even with a fresh download of the equivalent 64 bit build, highlighting does not work. So I will switch back to 32 bit (this is actually not the first problem I observe with Eclipse 64 bit).

Edit:

I thought this was the solution, so I installed the 32 bit version in C:\Program Files (x86) and set a shortcut in the "Start" menu. When I started Eclipse from there, highlighting again ceased to work. I now got it working again by deleting the .metadata directory in the workspace (i.e. resetting the workspace settings) and re-importing the projects.

Andreas Borg
  • 174
  • 4