I want to move a line to another specified in a variable.
So where I might do this to move the current line up seven lines:
:m-7
I want to do it with a variable line destination. Something like this:
:let lineOffset=-7
:m$lineOffset
Ultimately, I'm trying to append a collections of lines. So given this:
1
2
3
one
two
three
I want a simple way of getting this:
1 one
2 two
3 three
It seemed to me that the quickest way would be a macro. Something like this:
:m$(lineOffset)
kJ
$(lineOffset)j
:let lineOffset+=1
I know you can't use shell variable syntax as shown above. But used here for purpose of comprehension.
Where lineOffset
, using the example above, would be -3, so would move the current line 3 lines back when used as :m-3
.
And where those statements
- Move current line to line number specified by
lineOffset
(move sends the cursor to that line as well); - Move to line above moved line and join it with the moved line;
- Go to next line to be moved;
- Set the
lineOffset
to the next line down from the last.