Copy and paste content from one file to another file in vi

后端 未结 18 1481
南方客
南方客 2020-12-04 05:02

I am working with two files, and I need to copy a few lines from one file and paste into another file. I know how to copy (yy) and paste (p) in the same file. But that doesn

18条回答
  •  萌比男神i
    2020-12-04 05:15

    Here's one way to do it;

    • Start Vim and open file1 which is the file you're working on.
    • :e file2 which will bring up file2, the file you want to copy lines from.
    • locate the lines you want to copy. If it's three lines, you hit 3yy
    • :b1 this will switch to buffer 1, where file1 is
    • figure out where you want to insert the lines you yanked, and hit p

    You could have both files viewable too. Split the screen with e.g. Ctrl + w s.

    As for cutting, d cuts and places the cut stuff in the yank buffer. dd will "cut" a line.

提交回复
热议问题