'Place the rows of two blocks of text after each other alternatively
I have the following two blocks of text
abc
abc
cdz
zer
sdf
bfd
dss
azr
vvf
ezr
I want to know how I can place the rows of these two blocks alternatively so that I get the final block of text as following:-
abc
bfd
abc
dss
cdz
azr
zer
vvf
sdf
ezr
Solution 1:[1]
Using macro to move 1 line at a time:
- Start recording macro with your cursor on the 1st char of the 1st line
- Move cursor down x lines until the first line of the 2nd block (x=8 in this case)
8j - Cut this line using
Dinstead ofddto maintain the distance between the 2 blocksD - Move cursor up x lines to the first line
8k - Paste the line we just cut
o[esc]p - Move cursor to the next starting position (1st char of the next line)
j^ - End recording.
- Replay this macro on each line.
Solution 2:[2]
Here is a method inspired by this question:
Write each block to a separate temporary file:
vip :'<,'>w /tmp/a <motion> vip :'<,'>w /tmp/bCut the two blocks.
Insert the output of
paste::read !paste -d '\n' /tmp/a /tmp/b
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mkrieger1 |
| Solution 2 | romainl |
