325
votes

I have an odd problem. In Eclipse Ganymede, I used to be able to highlight a variable, and it would highlight the use of that variables in that method. However through some action I have now disabled it. Is there a way I can enable it?

I tried searching Google, but since I don't know what the feature is called, its kinda tough.

Its a really useful feature, and its annoying that its not working.

11
OK, ill try to make it more relevant next time. Just to satisfy my curiosity, what would you have used?Gerrie
after doing what the accepted answer says, you might have to restart eclipse for the changes to take effect.mathheadinclouds

11 Answers

620
votes

There's a little "highlighter" icon on the toolbar - it toggles "Mark Occurrences".

From the preferences window, the feature you mean is configured by navigating to:

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

screen shot

142
votes

There's a little "highlighter" icon on the toolbar - it toggles "Mark Occurrences".

You probably accidentally pressed it when trying to select a menu item at some point. I had a friend who did that with the "show selected element only" toolbar button...

You can either press it again or configure as Rytmis says.

107
votes

Press alt-shift-O.

It toggles the "Mark Occurrences" feature of Eclipse; which provides the highlighting functionality you're missing.

18
votes
  • In Eclipse Kepler,
    You can simply use the "Toggle Mark Occurrences" icon on the tool bar or you can use keyboard short cut alt+shift+O.

    enter image description here

  • Window > Preferences > Java > Editor > Mark Occurrences. Enable "Mark occurrences of the selected element in the current file" and click Apply.

    enter image description here

11
votes

On Mac OS it's opt-cmd-O I pressed that once by mistake, thanks to this question I found my way back

8
votes

I had this too and my Mark Occurrence options were already all checked. As always, try restarting Eclipse, it worked for me.

EDIT: It actually kinda worked. There's a bug on Eclipse that when you open a project in a new window (in case your first Eclipse window is a mess full of projects) it starts not to work. In case you need you can select an item and toggle the highlighter in the toolbar or use Alt+Shift+O, but you're gonna have to do it every time you select an item.

4
votes

In addition, you have to go to General->Editors->Text Editors->Annotations, choose Occurrences and check the "Text as" and choose Highlighted. This will make you happy.

2
votes

That is probably how the 'mark occurences' got turned off... I was using Ctrl+Shift+O to organize imports and by mistake chosen Alt instead of Ctrl. So it can be turned on again by Alt+Shift+O.

1
votes

I had a similar problem. I solved it by uninstalling the erlang plugin called "erlide".

1
votes

I had the similar problem where the references were not highlighted, on enabling the mark occurrences in windows-prefrences-java-editor I am able to highlight the references

0
votes

To me it didn't work anymore because there was an error in the code. It generally works, but sometimes it might not, make sure your code has no errors if nothing else works.