'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:

  1. Start recording macro with your cursor on the 1st char of the 1st line
  2. Move cursor down x lines until the first line of the 2nd block (x=8 in this case)
    8j
    
  3. Cut this line using D instead of dd to maintain the distance between the 2 blocks
    D
    
  4. Move cursor up x lines to the first line
    8k
    
  5. Paste the line we just cut
    o[esc]p
    
  6. Move cursor to the next starting position (1st char of the next line)
    j^
    
  7. End recording.
  8. Replay this macro on each line.

Solution 2:[2]

Here is a method inspired by this question:

  1. Write each block to a separate temporary file:

    vip
    :'<,'>w /tmp/a
    <motion>
    vip
    :'<,'>w /tmp/b
    
  2. Cut the two blocks.

  3. 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