(NOT a possible duplicate of Swap text around equal sign 🙂
Very often I find myself swapping things around. Which is a pain in the ass.
Let say just after I write this piece of code
tmp = realloc (words, sizeof (char **) * (*count + 1));
I notice there are just too many asterisks in a row, don’t like it, and want to swap the two factors around the multiplication asterisk.
Or, I write
#if !defined(_CONSOLE_H_) && defined (__MINGW32__)
but I suddenly realize that defined (__MINGW32__) must come first for some reason.
I think it would be cool if I could do something like this:
(On a character x, [x] indicate cursor position. <S> stands for this hypothetic “swap around” command)
#if [!]defined(_CONSOLE_H_) && defined (__MINGW32__)
command: vf&<S>$ => select from cursor to pivot (the word &&), and swap the selection around with the text till end of line.
Or, for the former example:
tmp = realloc (words, [s]izeof (char **) * (*count + 1));
command: v3f*<S>f) => select from here to third *, swap with text forward to ).
For me, it would be incredibly useful. Is there something like this out there, or I have to write my own plug-in?
Thanks!
EDIT –
As @ib. says in the comments to his answer, I need to be more specific as to what is the pivot.
The pivot could also be a character, for example here:
static char ** tokenize_input (char * input, PDWORD count);
I may want to swap the two arguments around the ",". More precisely, the ", ".
So maybe I’ll need two commands:
<s> - char-wise - the pivot is the last character of the selection;
<S> - word-wise - the pivot is the last word of the selection.
Thanks!
(ps. what about the last Word? 🙂
This seems to work here, let me know how it does:
No need to press enter to specify the movement now. The ‘pivot’ always includes any surrounding whitespace and it can be defined with a single character class given as argument to Swap() in the mapping.
If you want to see it highlighted, check https://gist.github.com/1921196