1

This question already has an answer here:

I have 2 data files f1.dat and f2.dat.

f1.dat

0 a0 b0
1 a1 b1
2 a2 b2

f2.dat

0 c0 d0 e0
1 c1 d1 e1
2 c2 d2 e2

I wish to copy all columns of f2 except the fist column to f1. f1 after merging will look like

f1.dat

0 a0 b0 c0 d0 e0
1 a1 b1 c1 d1 e1
2 a2 b2 c2 d2 e2

How would I instruct vim to accomplish this task?

marked as duplicate by Rich, Community Feb 2 '17 at 13:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

You can do it with the following sequence of keystrokes:

  • in f2.dat file:

    gg0w<C-v>G$y
    
  • in f1.dat file

    gg0$<C-v>G$A<Space><Esc>$p
    

Explanations:

  • first sequence:

    • gg0 - move to the beginig of the file
    • w - jump to second word
    • C-v - start blockwise visual selection
    • G - jump to last line of file
    • $ - jump to end of that line
    • y - copy selection
  • second sequence:

    • gg0 - move to the beginig of the file
    • $ - jump to end of line
    • C-v - start blockwise visual selection
    • G - jump to last line of file
    • $ - jump to end of that line
    • ASpaceEsc - append one space at the end of line. After pressing Esc this will be repeated on all lines of visual block.
    • $ - jump to end of line
    • p - paste content
  • Exactly what I was looking for. @Rich Thank you for the edit :) ... – Sathyam Feb 2 '17 at 13:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.