vim

How to append each line from 11-20 to each line from 1-10 in VIM


I have a file in which first 10 lines are the columns of a table and the rest 10 lines are the values of each column.

How can I use norm in VIM to append the values after each column names like this:

column1
...
column10
value1
...value10

-->

column1: value1
...
column10: value10

It is a little similar with this(Vim - Copy Nth word of each line, from line 10-100, to end of line), but I don't know how to go to line 1:10 and append the copied lines.

Any idea will be appreciated!


Solution

  • Fairly naive and crude way to do this, but:

    :1,10norm! 10j0d$10kA: ^[p
    

    Explanation:


    Another (copy-pastable) way, (ab)using the substitute command:

    :1,10s/\v(.*)\ze(.*\n){10}(.*)/\1: \3/ | 11,20d
    

    which does: