我如何在 Eclipse 中转到“下一次出现”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12588010/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 19:03:45  来源:igfitidea点击:

How do I go to "next occurrence" in Eclipse

eclipse

提问by machineghost

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.

在 Eclipse 中,您可以打开“Mark Occurrences”,然后它将突出显示当前范围内给定变量的每个出现。太好了,但我真的很想从一个这样的事件转移到下一个。

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).

到目前为止,我发现了两个关于如何做到这一点的建议,但都没有奏效。首先是这个 SO 帖子:Eclipse 导航到下一个/上一个标记的发生,它建议ctrl+k. 但是,这对我不起作用:在我的 Eclipse 中,键映射绑定到“查找下一个”,而不是“下一次出现”(Eclipse 键绑定中甚至似乎没有“下一次出现”,但是也许我没有用正确的名字称呼它)。

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).

然后我找到了一个论坛帖子,它建议单击工具栏中的黄色向上箭头并检查出现次数,然后使用ctrl+,. 如果它有效,这将是次优的,因为我已经ctrl+,习惯在错误/警告之间移动,但至少它会有所作为......但它根本不起作用(ctrl+,只是将我移到下一个警告)。

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

所以,我的问题是:如何在 Eclipse 中(最好通过键盘快捷键)从一个事件移动到下一个事件?

采纳答案by user1201210

You didn't mention how exactly ctrl+kdidn'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+kto 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+ksounds exactly like what you're looking for and I don't know the details of the difficulty you had with it.)

您没有提到究竟如何ctrl+k对您不起作用,但这是我在类似情况下使用的。我将光标放入或选择我在编辑器中查找的词,然后按ctrl+k将我移到下一个出现的词。由于下一个事件被选中,我可以使用相同的组合向前移动或按ctrl+shift+k(查找上一个)向后移动。(对不起,如果这听起来很傲慢,但ctrl+k听起来与您正在寻找的完全一样,我不知道您遇到的困难的详细信息。)

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.

祝你好运。

回答by Shawn Clark

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

有许多关于此的 SO 帖子。似乎有最好答案的一个是: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.

摘要:更改“下一个/上一个注释”选项(工具栏中的向上/向下箭头)以包含出现的事件,然后使用CTRL+,CTRL+.查找下一个出现的事件。

回答by Beez

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
  1. 将光标放在您要查找的单词上
  2. 命中alt+ shift+up
  3. 命中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 classand implementsin the following (it highlights the whole class):

不过,肯定有一些地方它不起作用。像classimplements下面(它突出了整个班级):

public class MyClass implements MyInterface {}

回答by Ilya Bobyr

There is a command "Occurrences in File" that is not bound to any key by default. You can run it by pressing Ctrl+3and then typing occurr. It will put all the current variable in the current file in the Search results. Now Ctrl+.and Ctrl+,will navigate through those occurrences, instead of through the warnings/errors list.

默认情况下,有一个命令“Occurrences in File”未绑定到任何键。您可以通过按Ctrl+3然后键入来运行它occurr。它将把所有当前变量放在搜索结果中的当前文件中。现在Ctrl+.Ctrl+,将浏览这些事件,而不是浏览警告/错误列表。

In order to go back you would want to clean search results. It seems this command does not have a key bound either. It is not even shown as a command in the Ctrl+3list. But you may also just do another search and it will overwrite the previous one results.

为了返回,您需要清理搜索结果。这个命令似乎也没有键绑定。它甚至没有显示为Ctrl+3列表中的命令。但您也可以再进行一次搜索,它会覆盖之前的搜索结果。

回答by user2772837

Use CTRL+Kto go to next occurrence and CTRL+SHIFT+Kto go to previous occurrence.

使用CTRL+K转到下一个发生,CTRL+SHIFT+K去前面的发生。