115

I tried using the Toggle mark occurrences (Alt + Shift + O) button and also in Preferences -> General -> Editors -> Text Editor -> Annotations and setting the C/C++ Occurrences and C/C++ Write occurrences. But still when I select a word it won't highlight all occurrences of that specific word.

What I am using is Eclipse Indigo Service Release 2 in XP, with a C++ project.

Adrian
  • 19,440
  • 34
  • 112
  • 219
  • 1
    The "Mark Occurences" options that everybody recommends will only highlight language tokens; it won't help you highlight a random word. See my answer for a 2016 possibility to highlight any word in any Eclipse pane. – hmijail Aug 18 '16 at 11:57
  • @hmijail, in the new Eclipse Oxygen it works natively! check my answer http://stackoverflow.com/a/42007441/658497 – Noam Manos Feb 02 '17 at 16:37
  • The glance plugin highlights any word in any pane, even if it is not an editor. The Oxygen functionality seems to just fix the highlighting that was broken or missing in JS editors. – hmijail Feb 02 '17 at 18:45
  • Possible duplicate of [Eclipse doesn't highlight references anymore](https://stackoverflow.com/questions/919614/eclipse-doesnt-highlight-references-anymore) – Organic Advocate Jul 06 '17 at 18:00
  • I also tried 'Alt + Shift + O'. The answer given by Mark gives you the 'Toggle Mark Occurrences' button, which on hovering shows 'Shift + Alt + O'. So, your shortcut key sequence is incorrect. – Shukant Pal Oct 27 '17 at 09:39

14 Answers14

289

You can try to activate Toggle Mark Occurrences with icon on Toolbar: Eclipse Toolbar

Mark
  • 17,887
  • 13
  • 66
  • 93
  • 2
    Ok, it seems this solution works when I create a simple new project, I tested on a big project and didn't work there don't know why. – Adrian Apr 25 '12 at 08:08
  • 9
    This solution is used only to toggle Mark Occurrences. Before to this Mark Occurrences have to enabled.You can enable it by going to Preferences --> Java --> Editor --> Mark Occurrences – Vins Mar 13 '14 at 08:59
  • This only worked after restarting eclipse. Prior to that, it would only work if I first selected the word and then toggled it on. I couldn't just keep it on. Now it's fine. – rimsky May 18 '16 at 19:19
  • 1
    This is great, do we have an option, after highlighting all occurrences, to edit/rename all of them at once? Kind of like what visual code does (using cmd + d) - please advise. Thanks. – Gel Jun 04 '19 at 18:35
  • That is another question, but on Windows: Alt+Shift+R – Mark Jun 06 '19 at 08:30
37

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

Jackie
  • 25,199
  • 6
  • 33
  • 24
21

In General > Editors > Text Editors > Annotations

enter image description here

RaiVikrant
  • 529
  • 6
  • 15
9

Check out options that are checked in Preferences -> Java -> Editor -> Mark occurrences. Then restart Eclipse.

Alexis Pautrot
  • 1,128
  • 1
  • 14
  • 18
4

The standard "Mark Occurrences" functionality included in Eclipse that everyone recommends only highlights identifiers in editors of whatever language. For example, it won't highlight int in C editors, and it won't help at all in the Console pane.

So if you want to highlight ALL occurrences on ANY word in ANY Eclipse pane (kinda like Notepad++ does), try the Glance plug-in for Eclipse.

As of November 2017 Glance works for Eclipse Neon and Oxygen. There was a period of time in which Neon was unsupported, and a fork appeared, but it seems unnecessary now (and abandoned).

hmijail
  • 1,069
  • 9
  • 17
  • Sadly I have to press Ctrl+Alt+F to highlight all occurrences with the Glance Plugin, but it's better than nothing. I'm using Parallel Fortran and it doesn't even have the options suggested in the other answers. – MasterHD Mar 24 '17 at 01:06
  • And in addition to Ctrl+Alt+F you must also have the word or token selected first. Nevertheless, better than nothing I guess. Such a feature is core in the majority of editors (but not Eclipse). Go figure. – wmoecke Nov 14 '18 at 20:01
4

Find the Preferences under Window,

main window - tab

In General > Editors > Text Editors > Annotations(1)

(5) is to select the color and press apply.

Preferences window

tk_
  • 16,415
  • 8
  • 80
  • 90
3

There are two ways to highlight all occurences. First is using Eclipse options, which is not very reliable, because in many versions of Eclipse it is not supported. Second is using a plugin called Glance which is available in Eclipse marketplace. This is supereasy and effective.

First Method

In the toolbar, there is button for Toggling Mark Occurrences. So, once you selected the text/word whose occurences you wish to highlight, then click this toggle button.

enter image description here

Let's say this step doesn't work for you. Then, Follow this step: Goto: Window ==> Preferences ==> General ==> Editors ==> Text Editors ==> Annotations ==> On right Annotations types box: Occurrences ==> Select all check boxes. enter image description here

You can also go to Window ==> Preferences ==> Java ==> Editor==> Mark Occurrences ==> Check all the checkboxes. enter image description here

Restart Eclipse and check if highlighting works. If still doesn't work, then Go to Second Method

Second Method From Eclipse marketplace, install Glance. Once installed, restart Eclipse. Now select any word in your eclipse editor

  1. Move focus to component where you want to search
  2. Open Glance using Ctrl + Cmd + F shortcut on Mac or Ctrl + Alt + F on other platforms
  3. Enter text you want to search
  4. Use Enter or **Shift + Enter** to find next/previous match
  5. Close search box using Esc enter image description here You can also customize Glance from Window ==> Preferences ==> Glance
Om Sao
  • 7,064
  • 2
  • 47
  • 61
  • "Glance" is no longer available/supported unless you find some old fork but then it probably won't work anyways in latest versions – Bostone May 17 '22 at 22:13
2

For Eclipse Mars:

Window --> Preferences --> Check (Mark occurrences of the selected element in the current file.)

As shown if figure:

enter image description here

Aftab
  • 2,863
  • 32
  • 41
2

Go

Java> Editor > Mark Occurrences

Uncheck "Keep Marks when the section changes" then click Ok

Restart Eclipse.

This work for me.

mfe
  • 1,158
  • 10
  • 15
0

If you go into the window-prefrences, select the language you want/are working with. Select the editor under this specific language and then there is a mark occurrences there that has some options. Where it says keep marks when the selection changes, for me this was checked. When I unchecked it the system started highlighting correctly.

NDEthos
  • 507
  • 6
  • 17
0

For folks who are using a dark background with light font colors, you may want to check out the highlight color in Preferences -> General -> Editors -> Text Editor -> Annotations. Mine was defaulted to black, which does not stand out on a black background.

Bryan Kahlig
  • 19
  • 1
  • 3
0

Glance does not work anymore, but in current Eclipse Versions (Eclipse 2020) you can highlight any word by selecting the word and pressing CTRL+F. The word is now highlighted. In the small search input, you can toggle 'match whole word' and case sensitivity.

tak3shi
  • 2,305
  • 1
  • 20
  • 33
0

I'd like to complement the other answers - which work in Java editor only or require plugins - with a way to highlight all occurrences of any text (not just a word or identifier) in any editor of text files (e.g. SQL, CSV, HTML, TXT, Java, etc ...).

There is a standard/built in command called Find Text in File (under Window -> Preferences -> Keys)

enter image description here

By default it has no keyboard shortcut assigned. Simply give it a shortcut (e.g. Ctrl+Alt+S) select some text (not necessarily a word) and it will find and highlight all occurrences of that selected text.

It can also be invoked from the menu as Search -> Text -> File.
Enjoy

oᴉɹǝɥɔ
  • 1,796
  • 1
  • 18
  • 31
-1
  1. Click the word and hold until a popup appears as shown in the figure.
  2. On the popup, there is a little right arrow, after clicking it, a new icon shows up.
  3. Click that link to open preferences.
  4. Once in preferences, select C/C++ Occurrences (it will be language specific) and select Include in next/previous navigation with Text as Highlighted.

This should enable the feature of highlighting all occurences of the selected word in the opened file.

spenibus
  • 4,339
  • 11
  • 26
  • 35
athyagat
  • 1
  • 1