Suppose I want to create a macro that swaps two function parameters.
For example, I search for swap:
And with the cursor pointing at the 's' in swap, I can search forward for the paren, move one to the right, delete everything up to the comma, move back to the (, use '%' to go to the ending ')', add another comma, paste the first parameter, then go back to the swap, and delete the comma that used to separate the first and second parameter.
/(<return> ld/,<return> h%i, <escape> p?(,<return> lx
(And I have made a quick-and-dirty macro for this.)
This works fine as long as the first parameter doesn't have parentheses in it. For example, this:
swap(foo, func(2, 3));
swap( func(2, 3), foo);
swap(func(2, 3), foo);
swap( 3, func(2), foo);
Because the parens in the first argument confuse the macro; it doesn't realize it should ignore the first comma because it's inside parens.
Anyway, my question is, is there a way to search for the next "," that isn't inside of parens? For example, one way would be to search for a regex [,(] that matches either a comma or opening paren; then if it found a paren, use % to skip forward to the matching closing paren, and then search forward again. Of course, that would require being able to conditionally loop, which is not really available within a macro (right?)
Or possibly, is there a way to search for a "," after a sequence containing equal numbers of right and left parens?
I was just hoping that something like this exists, given that % exists.