Invert Dictionary 2
Another way to switch the key-value pairs of a dictionary.
Before
var color_to_points = {
"red" = 0,
"orange" = 5,
"yellow" = 10,
"green" = 15,
"blue" = 20,
"purple" = 30,
"black" = 50,
}
After
var points_to_color = {
0 = "red",
5 = "orange",
10 = "yellow",
15 = "green",
20 = "blue",
30 = "purple",
50 = "black",
}
Preview
Command
webS_to_<enter><alt-(>
xt}S,|=<enter>_2<alt-(>
webselects the second word without whitespaceSsplits the selection on regex match. We type in_to_for the regex and hit<enter>to split it into two sections<alt-(>rotates the contents of the selectionsxselects the whole linet}selects until (but not including) the next "}" characterSsplits the selection on regex match. We type in,|=for the regex and hit<enter>to split it into sub-selections_trims trailing whitespace on all selections2<alt-(>rotates the contents of selections, but only between pairs of selections.