Replace String in all files in Eclipse

StringEclipseReplace

String Problem Overview


How can I search and replace a String in all files of my current project?

Let's say I have the string "/sites/default/" now I want it to be "/public/sites/default/", but there are almost 1000 files.

String Solutions


Solution 1 - String

  • Goto "Search"->"File" from menubar at the top left
  • Enter text, file pattern and projects
  • Click "Replace..." button at the bottom
  • Enter new text click ok

Voilà...

Solution 2 - String

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

A more consistent hotkey would be using the Alt method: Tap Alt, then A, then 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

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

Solution 3 - String

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

Solution 4 - String

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:

A demo at:

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

Solution 5 - String

Tonny Madsen said 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 + H and choose the "File Search" tab.
  • Enter text, file pattern and choose your Workspace or Working Set.

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:

enter image description here

  • Now, right-click on your selection and go to --> Replace Selected.... Here's a screenshot of that:

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.

enter image description here

Voilà!

References:

Solution 6 - String

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

enter image description here

Once you click on replace it will show as below

enter image description here

Solution 7 - String

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

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

Solution 8 - String

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.

Solution 9 - String

Ctrl+F gives me Find/Replace dialog box.

Or you can,

First Alt+A

Next Alt+F

Then press on Replace button.

If non of them worked:

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

Solution 10 - String

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

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRickMxView Question on Stackoverflow
Solution 1 - StringTonny MadsenView Answer on Stackoverflow
Solution 2 - StringAnonsageView Answer on Stackoverflow
Solution 3 - StringRoland TeppView Answer on Stackoverflow
Solution 4 - StringAlireza FattahiView Answer on Stackoverflow
Solution 5 - StringGabriel StaplesView Answer on Stackoverflow
Solution 6 - StringNikhil Kumar KView Answer on Stackoverflow
Solution 7 - StringChaminda BandaraView Answer on Stackoverflow
Solution 8 - StringFeng ZhangView Answer on Stackoverflow
Solution 9 - StringBlasankaView Answer on Stackoverflow
Solution 10 - StringChinmoyView Answer on Stackoverflow