Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 24008 - (automatic) Global Replace
Summary: (automatic) Global Replace
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Search (show other bugs)
Version: 2.0.1   Edit
Hardware: All All
: P3 enhancement with 15 votes (vote)
Target Milestone: 3.0   Edit
Assignee: Thomas M??der CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 32709 34300 44139 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-09-24 03:23 EDT by Victor Volle CLA
Modified: 2005-11-07 14:44 EST (History)
18 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Victor Volle CLA 2002-09-24 03:23:38 EDT
Currently it is only possible to do a global replace, by
first searching and then replace each occurrence manually.
While this ensures that nothing is accidentally replaced,
it is awful if you have use cases like the following:

- I want to replace "DAO" to "Dao" and "XML" to "Xml"
  in all methods, classes, attributes, local variables etc.
- I want to replace the copyright in all files
- I want to replace all 'รค' (german special character) to "ae" or "ä"
- I want to rename all classes that end with "Helper" to "Service"

These kinds of things happen quite frequently if you incorporate
code from one project into another because the responsibility
for the code has changed or after a merger of two groups/companies.
Often these to groups had different style guides that should now
be consolidated. Or imagine taking over the ORO and the OJB stuff
in the Jakarte project.

And even if it would be better to have refactorings, a pragmatic
approache sounds much better to me.
Comment 1 Dani Megert CLA 2002-09-30 04:21:36 EDT
Would it help if the Replace dialog would offer a "Replace in All Files..." button?
Comment 2 Victor Volle CLA 2002-09-30 06:02:36 EDT
It would help, to have such a button as a preliminary fix.
That's what I tried to do, but since I never did any Eclipse
hacking before, I did not achieve anything.

But from my point of view it is so strange and unusual not
to have a search dialogue with a replace 
possibility. I always have to serach, then select the found
files, right click and then replace/replace in all files ...

Anyway: for me a button "replace in all files" in the replace
dialogue would help me tremendeously.
Comment 3 Roel De Meester CLA 2002-11-29 07:22:23 EST
Any information on when this VERY VERY helpful feature would be implemented.
Right now I always use Together or VisualJ++ to do a find/replace on all my 
sources.  
Comment 4 Dani Megert CLA 2002-11-29 08:15:50 EST
It is currently not a high prio item for 2.1 (at most time permitting).
Comment 5 Dani Megert CLA 2003-02-24 12:09:41 EST
*** Bug 32709 has been marked as a duplicate of this bug. ***
Comment 6 Dani Megert CLA 2003-03-10 09:00:19 EST
*** Bug 34300 has been marked as a duplicate of this bug. ***
Comment 7 David Garcia CLA 2003-05-26 16:48:03 EDT
This is one of the main problems on the current version of Eclipse.
Nice to know that a new solution will be included for version 3.0.
As a SNiFF+ user (Windriver product) please consider the current
implementation of this feature in this product as a reference. 

In SNiFF+ the tool to find and replace in one or multiple files
is the Retriever. It's a windows divided in to main parts, in the
left you specify what you are looking for (using regular expressions).
The right part is also divided in two, in the top appears, grouped by file,
the line in where there is a match. In the bottom there is an editor for the
current selection on the top (so the Retriever includes the possibility
to find and edit in one window). 

It includes also de possibility to replace all the matches. The tool take care
of check out files (when working with a revision tool) if needed.

SNiFF+ info:
http://www.windriver.com/products/sniff_plus/index.html
Comment 8 Dani Megert CLA 2003-10-06 04:40:27 EDT
*** Bug 44139 has been marked as a duplicate of this bug. ***
Comment 9 Tim Koss CLA 2003-10-20 12:51:12 EDT
This pr is committed for 3.0
Comment 10 Jed Wesley-Smith CLA 2003-10-21 04:01:21 EDT
q. will this feature include RegExpressions? (ie. like 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=14277 and 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=33115)

basically, is this related to "Add regex content assist support for File search 
page" https://bugs.eclipse.org/bugs/show_bug.cgi?id=44280
Comment 11 Dani Megert CLA 2003-10-21 05:00:04 EDT
Find/Replace already allows this and therefore this one will probably also do so
(though not yet committed).
Comment 12 Dani Megert CLA 2003-11-18 08:21:59 EST
Global search is now possible. There's also a search button on the File search
page in the Search Dialog.

Replace using a regular expression is currently not yet supported (but you can
use  it for searching).
Comment 13 Thomas M??der CLA 2003-12-02 05:11:06 EST
Marking this one as fixed, since we have other bugs outstanding issues:

bug 37675
bug 47025
Comment 14 Michael O'Connor CLA 2004-07-26 05:59:15 EDT
This should be reopened.  Global search is possible, replace (*in one file at a 
time*) with regular expressions is possible, but this issue is different.

It is still not possible (I'm using Eclipse version: 3.0.0 Build id: 
200406251208) to perform a global replace on more than one file at a time.

I think this could best be implemented by adding a "Scope" panel, like the one 
in the Ctrl-H Search dialogue, to the Ctrl-F Find/Replace dialogue - enabling 
replace to be carried out on the currently-open file / workspace / 'enclosing 
projects' / woking set.
Comment 15 Lars Sonchocky-Helldorf CLA 2004-08-24 05:54:00 EDT
I think this should be reopened (I can't do this - why?) because global search 
and replace lacks the possibilty to do a multiline search and replace, e.g. the 
possibility to replace one ore more lines of text with one or more lines of 
text.

This should be doable by intializing the relevant org.eclipse.swt.widgets.Text 
input fields with SWT.MULTI instead of SWT.SINGLE

The layout of the search and replace dialog should be no issue since there is 
enough space left.


Example, where this is needed (to convince you that this feature request is no 
exotic hogwash):

Part of my dayjob is to turn static html which our webdesigners created into 
dynamic jsp. Hereby I often have to replace one or two lines of identic html in 
multiple files (typically some place holder image or texts) with several more 
lines of jsp-code.
Comment 16 Tom Sugden CLA 2004-11-04 06:28:05 EST
I agree that this should be reopened. Using Eclipse 3.1.0, I can't find any
multi-file find and replace functionality. Although there is now a "replace..."
button on the file search dialogue, I'm not sure what it does because there does
not seem to be anywhere to specify the text to replace the matches with. 

I agree that the easiest way to provide this functionality would be through a
scope option on the find/replace dialogue that included the option "all open
files". A more powerful find/replace could perhaps also be provided via the
search file dialogue.

At the moment I have to use the file search to find the required files, then
open them all individually in TextPad and use its find/replace functionality. 

Performing a manual find/replace across multiple files is also frustrating in
Eclipse, because sometimes the text in the find/replace dialogue's "find" input
box is automatically updated when changing file, so you have to type in the
"find" text repeatedly or re-select it from the drop down list.
Comment 17 Martin Aeschlimann CLA 2004-11-04 10:41:48 EST
There are two ways to do a global replace (in 3.0):
- Use the replace button on the search dialog: After searching you will get a 
new dialog to enter the replave string
- Use 'Replace...' on search matches in the search view

Please do not reopen bugs when you miss mutli-line search/replace, I filed a 
new bug for that (bug 77836).
Comment 18 Ed Zwart CLA 2005-09-10 19:28:19 EDT
I can't seem to include newline characters in the "With" field of the Replace
dialog.  Capture group characters works, but \n does not.  For example, I would
like to replace 

oldFunc();

with 

// oldFunc();
newFunc();

This example is trivial as I don't really need to use two lines.  I can do...

newFunc();  // oldFunc()

But I have reason to want to replace with multiline regexps.  Is this a bug?
Comment 19 Anon CLA 2005-11-07 14:44:23 EST
(In reply to comment #18)
> I can't seem to include newline characters in the "With" field of the Replace
> dialog.  Capture group characters works, but \n does not.  For example, I would
> like to replace 
> 
> oldFunc();
> 
> with 
> 
> // oldFunc();
> newFunc();

I'd like to see a solution to this too..
I need to be able to use regex on the "replace with" string as well.