Reputation: 25278
I have a common issue when working with code in the IDE:
string.Concat("foo", "bar");
and I need to change it to:
string.Concat("bar", "foo");
Often I have several of these that need to be swapped at once. I would like to avoid all the typing. Is there a way to automate this? Either a shortcut or some sort of macro would be great if I knew where to start.
Edit: changed to string.Concat to show that you can't always modify the method signature. I am only looking to change the order of the params in the method call, and nothing else.
Upvotes: 16
Views: 8640
Reputation: 135
I use an extension that does exactly this one thing.
It describes itself as
Allows arguments (or other comma separated lists contained in brackets, braces, etc.) to be shifted left and right.
https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.shifter
Upvotes: 2
Reputation: 4715
I had a lot of code with this function:
SetInt(comboBox1.Value + 1, "paramName", ...
SetInt(comboBoxOther.Value, "paramName", ...
And I needed to swap only the first two parameters;
I ended up using some text editor with regular expression management (like Scite), and using this one saved me hours:
Find: SetInt(\([.a-z0-9]+[ + 1]*\), \("[a-z0-9]+"\)
Replace: SetInt(\2, \1
Upvotes: 2
Reputation: 3248
<Ctrl>
+ <Shift>
+ <t>
will transpose two words, so it would work in your case. Unfortunately I don't see this working (without multiple presses) for functions with larger parameter lists...
Upvotes: 5