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.
1. Ctrl+Shift+P, F1 ⮕ Show Command Palette. This shortcut opens the command palette in the vs-code, where we can search for the other commands. For example, if someone is working on HTML and wants to format the lines of code, but he/she doesn't know the command then the command palette comes in handy to search commands ...
Use Change Signature, instead of Rename, to alter a parameter name in C/C++ so that parameter names in declarations and implementations remain consistent. If you rename a parameter using the Rename command, only the signature and body of an implementation are updated; the declaration is untouched.
Duplicate line. You can make the duplications of the same line using: Mac — Command + Shift + D. Windows/Ubuntu — Ctrl + Shift + D.
Ctrl + Shift + L to select all occurrences of current selection. Save this answer.
<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...
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With