Eclipse Quick Search 是 Eclipse IDE 中一个非常有用的功能,它允许开发者快速地在当前项目中搜索文本

Eclipse Quick Search 是 Eclipse IDE 中一个非常有用的功能,它允许开发者快速地在当前项目中搜索文本。这个功能可以帮助你找到特定的代码片段、注释、字符串等。使用 Quick Search,你可以:

  1. 打开搜索对话框:可以通过快捷键 Ctrl+H 或菜单栏的 “Search” -> “Quick Search” 来打开 Quick Search 对话框。
  2. 输入搜索内容:在搜索框中输入你想要查找的文本。
  3. 选择搜索范围:你可以选择在整个工作空间(Workspace)、选定的项目(Selected Resources)或者当前打开的文件(Opened Resources)中进行搜索。
  4. 执行搜索:点击 “Search” 按钮开始搜索。搜索结果会显示在下方的结果窗口中。
  5. 查看和导航结果:双击某个搜索结果可以快速跳转到该位置。

Quick Search 是一个强大的工具,可以帮助你更高效地浏览和编辑代码。
在Eclipse中使用正则表达式进行Quick Search的步骤如下:

  1. 打开Eclipse,点击菜单栏中的“搜索”选项,然后选择“快速搜索”。

  2. 在弹出的“快速搜索”对话框中,输入你想要搜索的文本。

  3. 如果你想使用正则表达式进行搜索,可以在输入框下方勾选“正则表达式”选项。

  4. 点击“搜索”按钮,Eclipse就会根据你的正则表达式进行搜索。
    在Eclipse中使用正则表达式进行文件搜索,可以通过以下步骤实现:

  5. 打开Eclipse IDE。

  6. 按下快捷键 Ctrl + H 或者从菜单中选择 Search > Search 来打开搜索对话框。

  7. 在搜索对话框中,切换到 “File Search” 选项卡。

  8. 在 “Search String” 输入框中输入你要搜索的文本。

  9. 勾选 “Regular expression” 复选框来启用正则表达式搜索模式。

  10. 根据需要设置其他搜索参数,如搜索范围、文件类型等。

  11. 点击 “Search” 按钮开始搜索。

通过以上步骤,你可以在Eclipse中使用正则表达式进行文件内容的搜索。
在Eclipse中保存常用的正则表达式可以通过以下步骤实现:

  1. 创建模板: 在Eclipse中,你可以使用代码模板(Code Templates)来保存常用的正则表达式。首先,打开Eclipse的首选项对话框(通过菜单栏选择“Window” -> “Preferences”)。

  2. 配置代码模板: 在首选项对话框中,导航到“Java” -> “Code Style” -> “Code Templates”。在这里,你可以创建新的模板或编辑现有的模板。例如,你可以创建一个名为“regexExample”的模板,并在其中插入你的常用正则表达式。

  3. 使用模板: 当你需要使用这个正则表达式时,只需在编辑器中输入模板的名称(如regexExample),然后按下Ctrl+Space键,Eclipse会自动展开为完整的正则表达式。

  4. 导出和导入模板: 如果你希望在不同的工作环境之间共享这些模板,可以将它们导出为XML文件,然后在其他Eclipse实例中导入。这可以通过“File” -> “Export” -> “General” -> “Preferences”来完成导出,通过“File” -> “Import” -> “General” -> “Preferences”来完成导入。

通过这种方式,你可以在Eclipse中高效地管理和使用常用的正则表达式,提高开发效率。

Engineering
Kris De Volder
July 11, 2013

Are you an Eclipse user? Do you want a fast and easy way to search for text snippets and patterns in your workspace? Then read on!

A new “Quick Search” is included in Spring ToolSuite (STS) 3.3.0 and Groovy Gails Tool Suite (GGTS) 3.3.0 which have just been released. Even if you are not a Spring or Grails developer, you might be interested in this Feature because it can also be installed separately into a vanilla Eclipse.
Introducing the Quick Search Dialog

The Quick Search dialog is designed to do just one thing and do it well: use simple text searches to quickly navigate around your workspace.

You open the dialog by pressing CTRL+SHIFT+L (or CMD+SHIFT+L on Mac):

The Power of Simplicity

Unlike the standard Eclipse search UI, QuickSearch UI is extremely simple. Nothing to configure (e.g. no need to define a search Scope create a workingset etc.). There’s just a single search text box. Start typing and see the results appear immediately and update instantly as you type. Use the arrow keys to select a result and press enter to navigate to it. You can also hit enter immediately to open the first result.

Of course you can also use the mouse if you want to, but there’s no need for your hands to leave the keyboard.

If you select a text snippet in an Eclipse Editor or View, that string will be automatically entered in the search box when you open Quick Search. Start typing to replace it. For example you can select a log or error message string in the console to quickly search for it:

If nothing is selected then your last search will be entered in the search box. This helps when you are repeatedly searching for the same pattern.
How did we make it so fast?

When you use the Quick Search dialog, results usually appear almost instantly and update instantly as you continue typing. All of this is done without using a search index and it even scales quite well on larger workspaces (e.g. our own workspaces containing all of STS and GGTS are rather large).

So how is this possible? Well, to be honest, we get a big boost because modern hardware is really quite fast. A fast CPU, a large amount of RAM and a good filesystem cache in the OS go a long way when you use heavily optimized native Java RegExp.

Another, more interesting part of the story is that the speed you ‘experience’ is actually a bit of an illusion. Worst case, you might paste a unique search term into the dialog and have to wait a few seconds as it searches all the files in your workspace. In practice you don’t hit this worst case very often. So let’s have a look at the two ‘tricks’ used behind the magic curtain. (Note: I don’t claim to have invented these techniques. I’m sure they have been used before to provide responsive search experiences. This article is about how I used these techniques to create a nice text search tool for myself and other Eclipse users.)

Trick 1: asynchronicity

As soon as you type the first character the search process is kicked of and it starts searching for matches to your query. Results are shown as soon as they are found. Typically single character searches will have many matches in just about any file. So, the dialog fills up instantly. To avoid the dialog from exploding the searcher will pause when it hits a limit of about 200 results.

When you type another character the search term is updated. But rather than restarting the search from scratch the search term is updated inside the running search process. That means any results going forward will match the new search term. But what about already found results? Well, far from being useless, we know they already contain the results of the new query! For example if we type “av” then anything containing “av” must obviously also contain “a”. So all we have to do to with results from old query “a” is filter out the results that don’t match the new query “av”. This is much faster then starting the search over again from scratch, because we only have to filter a relatively small number of in memory items rather than scan the file system again. Thus, the update as you type happens in an instant.

Trick 2: prioritization

The second trick is ‘prioritization’. If left to run, the Quick Search engine would eventually walk all the files in your workspace. But it tries to be smart in walking files you are probably more interested in first. The way we do that isn’t particularly sophisticated. We just prioritize based on the files currently open in editors. The highest priority is assigned to the ‘current active editor’. Then files open in other editors. Then files in the same folders alongside those files and so on.

That has two benefits. Firstly, it makes the search return interesting results faster. Second, it makes the more interesting results appear near the top of the list.
Tweaks and Options

Earlier I said there are no options to configure. I lied 😃. Quick Search actually doesn’t search all files in your workspace. There are quite a few things that it skips. This is good because it speeds up the search. Also, you probably don’t want to see results in those files anyway. For example, files in maven ‘target’ directies, ‘.git’ Git metadata directory etc. What gets skipped is configurable via a Preferences Page. Hopefully we got the defaults right so most users won’t need to change them. But if you need to, you can.

Installing

The Eclipse Quicksearch feature comes pre-installed with GGTS and STS (version 3.3.0 and above). It is part of the ‘eclipse-integration-commons’ project. However you can also install it separately into a Vanilla Eclipse because this Feature has no dependencies on other Spring project code.

For a separate install, you can get it from the Eclipse Market place (search for “Quick Search”). Or you can install directly from the update site. Open the Eclipse installer via Menu “Help >> Install New Software” and paste the update site url in the dialog (at the end of this article). Then select only the “Eclipse Quicksearch” Feature and hit the “Install” Button.

Links

Eclipse Update Site (note an update site link can’t be opened in a web browser. See installation instructions above):

http://dist.springsource.com/release/TOOLS/eclipse-integration-commons/

Feature requests, bug reports and general questions and feeback:

STS Forum: http://forum.springsource.org/forumdisplay.php?32-SpringSource-Tool-Suite

STS Issue tracker: https://issuetracker.springsource.com/browse/STS

if you are …

an Eclipse user

want a fast and easy way to search for text snippets and patterns in your workspace

… read on!

comments powered by Disqus

translate:
翻译:

您是Eclipse用户吗?你想用一种简单快捷的方法在你的工作区中搜索文本片段和模式吗?那就继续读下去!
一个新的“快速搜索”包含在刚刚发布的SpringToolSuite(STS3.3.0)和GroovyGailsToolSuite(GGTs3.3.0)中。即使您不是Spring或Grails开发人员,您也可能对这个特性感兴趣,因为它也可以单独安装到普通的Eclipse中。
介绍快速搜索对话框
“快速搜索”对话框的设计目的只有一个:使用简单的文本搜索在工作区中快速导航。
按CTRL+SHIFT+L(或Mac上的CMD+SHIFT+L)打开对话框:
简单的力量
与标准的Eclipse搜索UI不同,QuickSearch UI非常简单。无需配置(例如,无需定义搜索范围创建工作集等)。只有一个搜索文本框。开始键入并看到结果立即显示,并在键入时立即更新。使用箭头键选择结果,然后按回车键导航到该结果。您也可以立即按回车键打开第一个结果。
当然,你也可以使用鼠标,如果你想,但没有必要让你的手离开键盘。
如果在Eclipse编辑器或视图中选择一个文本片段,则当您打开快速搜索时,该字符串将自动输入到搜索框中。开始打字替换它。例如,您可以在控制台中选择日志或错误消息字符串以快速搜索它:
如果未选择任何内容,则将在搜索框中输入上次搜索。这有助于您反复搜索相同的模式。
我们是怎么做到这么快的?
使用“快速搜索”对话框时,结果通常会立即出现,并在继续键入时立即更新。所有这些都是在不使用搜索索引的情况下完成的,它甚至可以在更大的工作区(例如,我们自己的工作区包含所有STS和ggt都相当大)。
那么这怎么可能呢?好吧,老实说,我们得到了很大的提升,因为现代硬件真的很快。当您使用高度优化的本机Java RegExp时,OS中的快速CPU、大量RAM和良好的文件系统缓存会有很大的帮助。
故事中另一个更有趣的部分是,你“体验”的速度实际上是一种错觉。最坏的情况是,您可能会将一个唯一的搜索词粘贴到对话框中,并且在它搜索工作区中的所有文件时必须等待几秒钟。实际上,你不会经常碰到这种最坏的情况。所以让我们来看看魔术幕后使用的两个“把戏”。(注:我并不是说我发明了这些技术。我相信它们以前被用来提供响应式搜索体验。本文介绍了如何使用这些技术为自己和其他Eclipse用户创建一个不错的文本搜索工具
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值