copy and paste in vi

I don't have a huge amount of experience using VI. I am running it on Mac OSX.

I've copied and pasted text before in the editor using (when I say gui in the following I mean the Mac OSX gui)

  • Cursor to highlight and copy i using command C or the gui or the yy command in VI.
  • Entering insert mode where I want to paste the text and then pasting using command V or the gui
  • My problem is that a very long line that is split over multiple lines in the terminal becomes multiple lines as shown on the terminal when copied and pasted by any of the methods.

    How do I get it to copy and paste excatly as is?


    You have

     :set paste
    

    Put Vim in Paste mode. This is useful if you want to cut or copy some text from one window and paste it in Vim. This will avoid unexpected effects. Setting this option is useful when using Vim in a terminal, where Vim cannot distinguish between typed text and pasted text.


  • Move the cursor to the line from where you want to copy and paste contents at another place.
  • Hold the key v in press mode and press upper or lower arrow key according to requirements or up to lines that will be copied. you can press key V to select whole lines.
  • Press d to cut or y to copy.
  • Move the cursor to the place where you want to paste.
  • Press p to paste contents after the cursor or P to paste before the cursor.

  • Assuming your vi is actually vim, before pasting, do:

    :set paste
    

    That disables word wrapping and auto-indent and all similar things that modify typed text. After pasting, turn it off again with

    :set nopaste
    

    The reason is that while gvim can tell pasting from typing (so you don't need this when using gvim), the terminal version can't, because it's the terminal doing copy and paste and vim simply sees the text as typed. And therefore applies the transformation like it does for any other text.

    链接地址: http://www.djcxy.com/p/49506.html

    上一篇: 防止在vim中重复使用hjkl移动键

    下一篇: 复制并粘贴到vi中