I have found <a-)> and <a-(> really useful and fun key mappings to use. However, there have been situations where they aren’t sufficient for swapping certain selections. For example, transforming the following:
int foo(int a, float b, char* c);
into
int foo(float b, int a, char* c);
cannot be done by selecting the inside of the parentheses, splitting on , and rotating with either <a-)> or <a-(>. So I took the time to create a mapping that can do precisely that:
define-command shift-right %{ execute-keys -save-regs '^"a' 'Z<a-,>yz<a-)>Z,"aZz<a-,>RZ"az<a-z>a'}
define-command shift-left %{ execute-keys -save-regs '^"a' 'Z<a-,>yz<a-(>Z,"aZz<a-,>RZ"az<a-z>a'}
These commands allow you to move a single selection through the others. The result looks like this (brackets represent the main cursor):
[1] 2 3
2 [1] 3 (shift right)
2 3 [1] (shift right)
I think it is quite a neat binding that others might enjoy/find useful. I found it too small to be a plugin, so I decided to post it here such that others can find it quite easily. Some explanation on how it works:
Z<a-,>yzCreates a copy of all non-primary selections to reposition them later<a-)>Rotate all selections to the right, this is to get the main selection to the right.Z,"aZCreates a copy of all selections after rotation and creates a copy of the main selection in registerato get it back laterz<a-,>RRestore all rotated selections and replace all but the main selection with the clipboard (this keeps all of the selection contents ordered)Z"az<a-z>aSave all current selections and restore the main selection. Only then add back the rotated selections. This done in order to keep main selection at the same item.
There is probably a simpler way to achieve the same thing. I got this result through trial and error.