Is there a dedicated way to merge two blocks of text by interleaving lines, like passing from this:
a1
a2
a3
a4
b1
b2
b3
b4
to that:
a1
b1
a2
b2
a3
b3
a4
b4
in a few commands?
EDIT: I really like Sato Katsura's solution, here is how I have implemented it:
function! Interleave()
" retrieve last selected area position and size
let start = line(".")
execute "normal! gvo\<esc>"
let end = line(".")
let [start, end] = sort([start, end], "n")
let size = (end - start + 1) / 2
" and interleave!
for i in range(size - 1)
execute (start + size + i). 'm' .(start + 2 * i)
endfor
endfunction
" Select your two contiguous, same-sized blocks, and use it to Interleave ;)
vnoremap <pickYourMap> <esc>:call Interleave()<CR>
scroll-binding
two Vim windows.b1
, then I hitvip
to select the whole chunk, then,it
which is the<map-I've-Picked>
. Is it not working on your side?:'<,'>call Interleave()
. This caused a bunch ofStart past end
andE714: List required
errors. Taking a closer look at the mapping, I see now that I should have hit <esc> once before invoking the function, which works as expected