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

后端 未结 18 1502
南方客
南方客 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条回答
  •  半阙折子戏
    2020-12-04 05:22

    The below option works most of time and also for pasting later.

     "xnyy
    x - buffer name
    n - number of line to Yank - optional
    

    The lines yanked will be stored in the buffer 'x'. It can be used anywhere in the edit.

    To paste line(s) in the other file,

    :e filename&location
    

    Example: Type the below command in the current edit

    :e /u/test/Test2.sh
    and paste using "xP
    P - before cursor
    p - after cursor
    

    Complete operation

    open file 1 :

    vi Test1.sh
    
    a10yy
    
    -Yanked 10 lines
    

    -now open the second file from the current edit

    *:e /u/test/Test2.sh*
    

    -move the cursor to the line where you have to paste

    *"ap*
    

    --Lines from the buffer '*a*' will be copied after the current cursor pos

提交回复
热议问题