Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm refactoring some old code. I used really short names for local variables, which I'm coming to regret. Is there an easy way to rename local variables in scope using Wolfram workbench?

Here is an example

How could I change d inside Test, but not in the Print statement?

(*Some other code*)

Or the same for l inside Module?

(*Some other code*)

There is a Ctrl+1 QuickFix rename variable, which I discovered while researching this question, but it seems to work only on the whole file...

Using WB 2.0 (anybody even still uses WB 1.1?)

share|improve this question
@b.gatessucks Because the the d in test and the d in some other module have different functions. This is a simplified example. In real life I have several "functions", which all have the variable data. But in each function I would like to change data to some specific, more meaningful, name. – Ajasja Jan 16 '13 at 15:51
I would suggest a two stage procedure: first use the refactoring functionality to replace the symbol with one with a longer, unique name for the whole file. Then select each of the Modules and use the standard eclipse search and replace functionality to (string-)replace the unique longer symbol name with the desired new name which will let you act on the selected lines only... – Albert Retey Jan 16 '13 at 22:42
@AlbertRetey Well, what I'm doing at the moment is copying each module to a temp .m file, do the replacements there and copy back. – Ajasja Jan 17 '13 at 8:37
up vote 2 down vote accepted

I don't know if this works in all cases: If you highlight a region with the mouse and press Ctrl+F for the "find and replace", this will only search for words inside the highlighted area. This also works for the replace then. I tried it with a small example and it worked.

share|improve this answer
Yes, this works in all cases (you have to make sure that scope is set to selected lines). Also whole word and perhaps match case should be set under the options in the find/replace dialog. Then it mimics the rename quite well. – Ajasja Jan 17 '13 at 8:35
Perfect. I wonder if there is some other possibility using "Refactor". I tried to use the Refactor > Pattern Replace on a code selection, but it applies to the whole code instead of only the selection... – g3kk0 Jan 17 '13 at 8:40
Well, I guess I'll accept the Ctrl+F as the best that can be done. – Ajasja Jan 21 '13 at 8:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.