With the following code:
static final FooBar FOOBAR = ...;
and desire to modify the name of the Class and the variable it should be
possible to do this in a single Find and Replace by using:
find text: foobar
replace text: mooBlah
should result in a code:
MooBlah mooBlah ;
static final MooBlah MOOBLAH = ...;
Notice how the case of the original Class name, variable and static final
variable and the uppercase B in replacement text were used as hints to achieve
This is supported by emacs and is described like this in the emacs manuals:
20.9.3 Replace Commands and Case
If the first argument of a replace command is all lower case, the command
ignores case while searching for occurrences to replace—provided case-fold-
search is non-nil. If case-fold-search is set to nil, case is always
significant in all searches.
In addition, when the newstring argument is all or partly lower case,
replacement commands try to preserve the case pattern of each occurrence.
Thus, the command
M-x replace-string <RET> foo <RET> bar <RET>
replaces a lower case ‘foo’ with a lower case ‘bar’, an all-caps ‘FOO’
with ‘BAR’, and a capitalized ‘Foo’ with ‘Bar’. (These three alternatives—
lower case, all caps, and capitalized, are the only ones that replace-string
If upper-case letters are used in the replacement string, they remain upper
case every time that text is inserted. If upper-case letters are used in the
first argument, the second argument is always substituted exactly as given,
with no case conversion. Likewise, if either case-replace or case-fold-search
is set to nil, replacement is done without case conversion.
Also see: http://www.netbeans.org/issues/show_bug.cgi?id=80798
*** Issue 80798 has been marked as a duplicate of this issue. ***
*** Issue 90387 has been marked as a duplicate of this issue. ***
*** Issue 117771 has been marked as a duplicate of this issue. ***
*** Issue 125144 has been marked as a duplicate of this issue. ***
Please see all the duplicates for different descriptions of the same usecase.
This definitely gets my vote. IntelliJ does this already. Very nice feature to have work manipulating large codebases.
*** Bug 199989 has been marked as a duplicate of this bug. ***
This gets my vote. Any chance of pushing this into version 7.1? On the face of it it sounds rather easy to implement.
I will implement this for to nb 7.1
I implemented preserve case to netbeans search and replace.
It has its own checkbox which is disabled if matchcase or regexp is selected.
For example you search for foobar to replace by someElse
FOOBAR -> SOMEELSE
foobar -> someelse
FooBar -> SomeElse
fooBar -> someElse
fOOBAR -> sOMEELSE
Please notice upper case in someElse.
Hope you like it.
Integrated into 'main-golden'
User: Milutin Kristofic <email@example.com>
Log: #80732 - Support Emacs style case sensitive find and replace - preserve case in ctrl+h search and replace dialog