vim : copy one entire column from one file to another file

379 views Asked by At

File #1:

F#1  A1  B1  C1
F#1  A2  B2  C2
F#1  A3  B3  C3
F#1  A4  B4  C4
F#1  A5  B5  C5
F#1  A6  B6  C6

File #2:

D1  E1  F1
D2  E2  F2
D3  E3  F3
D4  E4  F4
D5  E5  F5
D6  E6  F6

The wanted format in File#2:

F#1  D1  E1  F1
F#1  D2  E2  F2
F#1  D3  E3  F3
F#1  D4  E4  F4
F#1  D5  E5  F5
F#1  D6  E6  F6

In vim, how to copy the entire column (1st column in this example) from File #1 to File #2, as in the wanted format shown above? Note that, in reality, the file is very long.

Thank you.

1

There are 1 answers

0
Eran Friedman On

Blockwise visual mode (CTRL-v) can help you achieving this (:help v for documentation).

The sequence of commands should be:

  1. Go to the top-left corner.

enter image description here

  1. Press CTRL-v. You should be in "VISUAL BLOCK" mode.

enter image description here

  1. Press G - it will take you to the end of file.

enter image description here

  1. Press l to mark the column (4 times in this case).

enter image description here

  1. Press y to copy this column.

  2. Open the second file (:e <second-filename>).

  3. Go to the top left corner and press P to paste the column.