325

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.

3
  • 3
    OK, ill try to make it more relevant next time. Just to satisfy my curiosity, what would you have used?
    – Gerrie
    Jun 4, 2009 at 12:20
  • possible duplicate of Eclipse does not highlight matching variables
    – Nateowami
    Dec 27, 2014 at 9:48
  • after doing what the accepted answer says, you might have to restart eclipse for the changes to take effect. Jan 11, 2015 at 10:34

11 Answers 11

621

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

6
  • 23
    Protip: the options dialog has a nifty find-as-you-type search, that's how I found it too. :)
    – Rytmis
    May 28, 2009 at 8:04
  • 2
    works for PHP too if you go to window -> preferences -> php -> editor -> mark occurences
    – max4ever
    Sep 28, 2011 at 15:31
  • 1
    Thank you very much! Works for CDT as well: window -> preferences -> c/c++ -> editor -> mark occurences
    – xmoex
    Jun 14, 2012 at 15:47
  • Similarly for Aptana studio: Window->Preferences->Aptana->Editors->{php|javascript|html ...} Source: Toggle Mark Occurrences button is greyed out
    – sumid
    Mar 12, 2013 at 18:06
  • 1
    If none of comments above worked, uncheck "Mark occurrences of the selected element in the current file" > Apply > OK. Go back to preferences, check "Mark occurrences of the selected element in the current file" > Apply > OK.
    – realPK
    Feb 4, 2015 at 23:04
142

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.

3
  • For aptana studio is this button greyed-out. You have to do that in menu.
    – sumid
    Mar 12, 2013 at 18:08
  • I liked this answer more than the accepted answer, since this satisfied the mystery behind: "How could I have possibly switched off the feature when I never opened the preferences window in years" Oct 25, 2013 at 13:02
  • oops I accidentally pressed it :P Sep 14, 2017 at 13:35
108

Press alt-shift-O.

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

0
20
  • 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

1
  • And if you encounter this problem even if you have the options checked, so: 1) "uncheck">"apply" . 2) "check" > "apply"
    – Farah
    Oct 31, 2014 at 15:12
12

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

0
8

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.

1
  • I have encountered this bug as well. Instead of restarting eclipse, you can also follow the advice on this page and disable mark occurrences and then re-enable it.
    – lifeson106
    Mar 20, 2014 at 14:23
4

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.

1
  • This allows you to choose the way occurrences appear on screen. Highlighted was preset for me. Probably the default.
    – misiu_mp
    Mar 8, 2011 at 12:14
3

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
  • The same mistake I have done, but to highlight the occurrence of a file I used Rename shortcut of occurrences Ctrl + Alt + r. Thanks yous post helped me lot. ):-
    – Yash
    Sep 29, 2015 at 9:40
1

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

1
  • 3
    Thanks, I shall forward that to my erlang fanatic friend. Though I am sure he doesn't use eclipse.
    – Gerrie
    May 6, 2013 at 11:29
1

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

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.