[java] Eclipse does not highlight matching variables

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.

This question is related to java eclipse

The answer is


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


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


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


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/


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.


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)


Java - Editor - Mark Occurrences in Eclipse Photon.

Java - Editor - Mark Occurrences

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


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.


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.


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.


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


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.

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


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


Using Alt + Shift + o It works for me!


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