0

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
Shawn Brar
  • 1,346
  • 3
  • 17
  • Isn't there a way in which I can just paste all of the 2nd block rather than doing it one by one? This is because the blocks that I actually have are a lot bigger and it will take a lot of time doing that. – Shawn Brar Apr 14 '22 at 08:49

2 Answers2

2

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.
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
lifubeam
  • 58
  • 4
0

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
    
romainl
  • 186,200
  • 21
  • 280
  • 313