I want to write a Vim Script which can achieve the following function, which is my favorite feature in some IDE. Say I have the following example code:
I'm a line and I just stay here.
I'm another line and I also stay here.
I'm the line to be selected and swapped upward 1. (1)
I'm the line to be selected and swapped upward 2. (2)
Then I can move the cursor to line (1)
and Vj
to select both (1), (2)
, then now I can hold some custom key combination, say ⌘ + option + k, and I hit these combination twice, then the expected result will be:
I'm the line to be selected and swapped upward 1. (3)
I'm the line to be selected and swapped upward 2. (4)
I'm a line and I just stay here.
I'm another line and I also stay here.
(1)
(2)
(The idea of swap selected lines downward is similar so I skip it.)
To avoid re-invent the wheel, is there any plugin already done this feature for us? If not, what are required for me to learn to write the above function?