How does one sort code blocks associated with each case (as part of a large switch case construct) on the basis of the case label?
What I want is to transform -
switch(val)
{
case C_LABEL:
/* do something */
break;
case A_LABEL:
/* do something else*/
break;
case B_LABEL:
/* do something really different */
break;
default:
printf("'val' not recognized");
}
into -
switch(val)
{
case A_LABEL:
/* do something else */
break;
case B_LABEL:
/* do something really different */
break;
case C_LABEL:
/* do something */
break;
default:
printf("'val' not recognized");
}
Turn each case into a one liner:
:fromline,tolineg/case/.,/break/s/\n/§
Sort them:
:fromline,tolinesort
Reformat them:
:fromline,tolines/§/\r/g
Notes:
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