Replace String in all files in Eclipse
StringEclipseReplaceString 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:
- Ctrl+C the text you want to do the replacing (if available)
- Highlight the text you want to be replaced
- Tap ALT, then A, then F. Brings you to File Search. The selection from (2) will auto-fill the search box
- In the “File name patterns” input box, type in “.java” for replacing all Java files or type in "" to replace in all files
- Click “Replace…”
- Ctrl+V (Paste). Or type in the value you want to do the replacing
- 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:
- Search what you want
- In the search tab right click and select replace , or replace all:
A demo at:
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:
- Now, right-click on your selection and go to --> Replace Selected.... Here's a screenshot of that:
- 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.
Voilà!
References:
- Here's the tutorial I came across that taught me this: http://www.avajava.com/tutorials/lessons/how-do-i-do-a-find-and-replace-in-multiple-files-in-eclipse.html?page=2
Solution 6 - String
ctrl + H will show the option to replace in the bottom .
Once you click on replace it will show as below
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.