string 替换 Eclipse 中所有文件中的字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6800799/
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-09 01:10:46  来源:igfitidea点击:

Replace String in all files in Eclipse

stringeclipsereplace

提问by RickMx

Do you know how can I search an replace a String in all files of my current project?

您知道如何在当前项目的所有文件中搜索替换字符串吗?

Lets say I have this string "/sites/default/ now I want it to be "/public/sites/default

假设我有这个字符串 "/sites/default/ 现在我希望它是 "/public/sites/default

but there are almost 1000 files.

但有近 1000 个文件。

回答by Tonny Madsen

  • "Search"->"File"
  • Enter text, file pattern and projects
  • "Replace"
  • Enter new text
  • “搜索”->“文件”
  • 输入文本、文件模式和项目
  • “代替”
  • 输入新文本

Voilà...

瞧...

回答by Anonsage

Depending on the file type you are focused on, Ctrl+H will open up different types of search screens.

根据您关注的文件类型,Ctrl+H 将打开不同类型的搜索屏幕。

A more consistent hotkey would be using the Alt method: Tap Alt, then A, then F.

更一致的热键是使用 Alt 方法:点击 Alt,然后是 A,然后是 F。

Efficient Order of Operations:

高效的操作顺序:

  1. Ctrl+C the text you want to do the replacing (if available)
  2. Highlight the text you want to be replaced
  3. Tap ALT, then A, then F. Brings you to File Search. The selection from (2) will auto-fill the search box
  4. In the “File name patterns” input box, type in “.java” for replacing all Java files or type in "" to replace in all files
  5. Click “Replace…”
  6. Ctrl+V (Paste). Or type in the value you want to do the replacing
  7. Enter
  1. Ctrl+C 要替换的文本(如果可用)
  2. 突出显示要替换的文本
  3. 依次点击 ALT、A 和 F。将您带到文件搜索。(2) 中的选择将自动填充搜索框
  4. 在“文件名模式”输入框中输入“ .java”替换所有Java文件或输入“”替换所有文件
  5. 点击“替换...”
  6. Ctrl+V(粘贴)。或者输入你想要替换的值
  7. 进入

You can find more details in my blog post: http://blog.simplyadvanced.net/android-how-to-findreplace-in-multiple-files-using-eclipse/

您可以在我的博客文章中找到更多详细信息:http: //blog.simplyadvanced.net/android-how-to-findreplace-in-multiple-files-using-eclipse/

回答by Roland Tepp

Use Ctrl+H for opening Eclipse search dialog, select appropriate search tab and select "Replace..." to get you to the "Search and replace" dialog

使用 Ctrl+H 打开 Eclipse 搜索对话框,选择适当的搜索选项卡并选择“替换...”以进入“搜索和替换”对话框

回答by Alireza Fattahi

Strange but it is a two step task:

奇怪,但这是一个两步任务:

  1. Search what you want
  2. In the search tab right click and select replace , or replace all:
  1. 搜索你想要的
  2. 在搜索选项卡中右键单击并选择 replace ,或全部替换:

A demo at:

演示在:

http://www.avajava.com/tutorials/lessons/how-do-i-do-a-find-and-replace-in-multiple-files-in-eclipse.html

http://www.avajava.com/tutorials/lessons/how-do-i-do-a-find-and-replace-in-multiple-files-in-eclipse.html

回答by Gabriel Staples

Tonny Madsensaid it right, but sometimes this is too simplistic.

托尼·马德森说得对,但有时这太简单了。

What if you want to be more selective in your replacements since not all replacements are correct for what you're trying to do?

如果您想在替换时更有选择性,因为并非所有替换都适合您要执行的操作,该怎么办?

Here's how to get more granularity to do the replacements only in certain folders, files, or instances:

以下是如何获得更多粒度以仅在某些文件夹、文件或实例中进行替换:

First, do like he said:

首先,像他说的那样做:

  • Click Search--> File...OR press Ctrl+ Hand choose the "File Search" tab.
  • Enter text, file pattern and choose your Workspace or Working Set.
  • 单击Search-->File...或按Ctrl+H并选择“文件搜索”选项卡。
  • 输入文本、文件模式并选择您的工作区或工作集。

Then:

然后:

  • Click Search
  • When your results come up, make some folder, file, or instance selections by Ctrl+ clicking on the ones you'd like to select. Ex: here's my selection. I've chosen 3 instances, 1 file, and 1 folder:
  • 点击 Search
  • 当您的结果出现时,通过Ctrl+ 单击您想要选择的文件夹、文件或实例进行选择。例如:这是我的选择。我选择了 3 个实例、1 个文件和 1 个文件夹:

enter image description here

enter image description here

  • Now, right-click on your selection and go to --> Replace Selected.... Here's a screenshot of that:
  • 现在,右键单击您的选择并转到 --> Replace Selected...。这是一个截图:

enter image description here

enter image description here

  • Enter what you'd like to replace it "With". In my case you can see it says it is "Replacing 190 matches in 4 files". Now click OK.
  • 输入您要替换的内容“With”。在我的情况下,您可以看到它说它是“替换 4 个文件中的 190 个匹配项”。现在点击OK

enter image description here

enter image description here

Voilà!

瞧!

References:

参考:

回答by Nikhil Kumar K

ctrl + H  will show the option to replace in the bottom . 

enter image description here

enter image description here

Once you click on replace it will show as below

单击替换后,它将显示如下

enter image description here

enter image description here

回答by Chaminda Bandara

There is an option in search => fileand shortcut is Ctrl+H. Go for further refer follow link. This is work fine with Eclipse Neon

search => file 中有一个选项,快捷方式是Ctrl+ H。进一步参考以下链接。这适用于Eclipse Neon

Is there a way to find/replace across an entire project in Eclipse?

有没有办法在 Eclipse 中的整个项目中查找/替换?

回答by Feng Zhang

If you want to replace two lines of code with one line, then this does not work. It works in notepad++. I end up open all files in notepad++ and replaced all.

如果你想用一行替换两行代码,那么这行不通。它适用于记事本++。我最终在记事本++中打开所有文件并替换了所有文件。

回答by Blasanka

Ctrl+Fgives me Find/Replace dialog box.

Ctrl+F给了我查找/替换对话框。

Or you can,

或者你可以,

First Alt+A

第一Alt+A

Next Alt+F

下一个Alt+F

Then press on Replacebutton.

然后按替换按钮。

If non of them worked:

如果他们都没有工作:

Goto -> Window -> Preferences -> General -> Keysand search for replacethen you will see binding for Find and replace. In the bottom of that window, you can add your key to Bindingtext box. There you can add or edit any keys as shortcut.

转到 -> Window -> Preferences -> General -> Keys并搜索replace然后您将看到Find and replace 的绑定。在该窗口的底部,您可以将密钥添加到绑定文本框。在那里您可以添加或编辑任何键作为快捷方式。

回答by Chinmoy

I have tried the following option in Helios Version of Eclipse. Simply press CTRL+F you will get the "Find/Replace" Window on your screen

我在 Eclipse 的 Helios 版本中尝试了以下选项。只需按 CTRL+F,您就会在屏幕上看到“查找/替换”窗口

enter image description here

enter image description here