Replace String in all files in Eclipse

前端 未结 10 1358
情歌与酒
情歌与酒 2020-12-02 05:37

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/si

相关标签:
10条回答
  • 2020-12-02 06:07

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

    0 讨论(0)
  • 2020-12-02 06:07

    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
    0 讨论(0)
  • 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/

    0 讨论(0)
  • 2020-12-02 06:14

    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.

    0 讨论(0)
  • 2020-12-02 06:18

    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

    0 讨论(0)
  • 2020-12-02 06:19

    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?

    0 讨论(0)
提交回复
热议问题