Vim: pasting lines line by line

commandeditorsvim

Let's suppose I have a file containing:

xxx
yyy
zzz

and another file:

kkk
qqq
ppp

I want to obtain:

xxxkkk
yyyqqq
zzzppp

Is that possible in Vim with some command? (I've tried using VISUAL BLOCK but with no success).

In my particular case I have two big files with many lines to paste so the answer could also be some shell command but i would like to know if there's a way to do it even within the same file.

Best Answer

From the command line, you could try

paste -d '\0' file1 file2 > file3

That does exactly what you want.

Visual Block mode in vim is also perfectly suited for this task. Are you sure you did it correctly? You should

  • Go to visual block mode
  • Select text and press y for yanking
  • Go to the other file, on the upper left corner of the to be paste data (last x) and press p.
Related Question