Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I go to "next occurrence" in Eclipse

Tags:

eclipse

In Eclipse you can turn on "Mark Occurrences", and then it will highlight every occurrence of a given variable in the current scope. That's great, but I'd really like to move from one such occurrence to the next.

I've found two suggestions on how to do this so far, and neither have worked. First there was this SO post: Eclipse navigate to next/previous marked occurrence, which suggested ctrl+k. However, that doesn't work for me: in my Eclipse that key-mapping is bound to "find next", not "next occurrence" (there doesn't even seem to be a "next occurrence" in the Eclipse keybindings, but maybe I'm not calling it by the right name).

Then I found a forum post which suggested clicking on the yellow up arrow in the tool bar and checking occurrences, then using ctrl+,. This would have been sub-optimal if it had worked, because I already use ctrl+, to move between errors/warnings, but at least it would have been something ... but it didn't work at all (ctrl+, just moved me to the next warning).

So, my question is: how can I move (preferably via keyboard shortcut) from one occurrence to the next in Eclipse?

like image 602
machineghost Avatar asked Sep 25 '12 17:09

machineghost


People also ask

How do I change occurrences in Eclipse?

Press ctrl + f for windows computer. Then under FIND, type what you want to find. Then in REPLACE WITH, type in what you want to replace it with. Then click REPLACE ALL.

What is Ctrl Shift G in Eclipse?

Search – Eclipse Shortcuts CTRL SHIFT G – Search for current cursor positioned word reference in workspace. CTRL H – Java search in workspace.

What does Ctrl Shift t do in Eclipse?

Switching between Open Editors Ctrl + Page Up and Ctrl + Page Down—Navigate to previous or next file from the list of open files. Ctrl + Shift + T—Display a list of classes from the workspace. Ctrl + Shift + R—Display a list of resources from the workspace.


3 Answers

You didn't mention how exactly ctrl+k didn't work for you, but it's what I use in similar circumstances. I put the cursor into or select the word that I'm looking for in the editor and then press ctrl+k to move me to the next occurrence. Since the next occurrence gets selected, I can use the same combination to move forward or press ctrl+shift+k (Find Previous) to move back. (Sorry if that sounds patronizing, but ctrl+k sounds exactly like what you're looking for and I don't know the details of the difficulty you had with it.)

I agree about the other combinations. If I have to take my hand off the keyboard, I may as well use the scrollbar.

Best of luck.

like image 155
user1201210 Avatar answered Sep 28 '22 00:09

user1201210


There are a number of SO posts around this. The one that seems to have the best answer is: https://stackoverflow.com/a/12767327/2836515

Summary: Change the "Next / Previous Annotation" option (Up / Down arrow in the toolbar) to include occurrences and then use CTRL+, or CTRL+. to find next occurrence.

like image 34
Shawn Clark Avatar answered Sep 28 '22 01:09

Shawn Clark


You can do this to maybe reduce some keystrokes/mouse clicks in selecting the initial word:

  1. Put the cursor on the word you're looking for
  2. Hit alt + shift + up
  3. Hit ctrl + k

This highlights the current word and then does a find next. It doesn't seem to be case-sensitive, though, but that's a small price to pay.

There are definitely some places it doesn't work, though. Like class and implements in the following (it highlights the whole class):

public class MyClass implements MyInterface {}
like image 23
Beez Avatar answered Sep 28 '22 01:09

Beez