user1164199
user1164199

Reputation: 379

How to rename many variable names at once (C/C++)

Is there a tool that will allow me to rename a large number of variable names at once?

I have a large number of variables that I want to put into a C structure and therefore, I would need to add a parameter to the beginning of each name included in the structure.

Upvotes: 1

Views: 6491

Answers (3)

Caleb
Caleb

Reputation: 125007

Is there any tool that will allow me to rename a large number of variable names at once.

Every half-decent IDE has a feature for this. You said that you're using Eclipse, so you can select the variable that you want to rename and then use the Refactor command to change the name in all your files.

Upvotes: 0

Jamie
Jamie

Reputation: 7431

sed with find, in a shell terminal, as in:

$ find /path/to/project/root -name "*.[ch]" -exec sed -ri 's/original_name/new_name/' {} \;

Upvotes: 1

Sebastian Redl
Sebastian Redl

Reputation: 72054

If you really want to do it at once, put a regular expression into your advanced search/replace function. ^(name1|name2|name3)$ ought to work. But no guarantee that it won't catch other things besides variable uses (in particular, the variable declarations). If you want that, you would have to work with something like Clang's tooling.

Upvotes: 1

Related Questions