Copy all the lines to clipboard

Is there any way to copy all lines from open file to clipboard in VI editor. I tried yG but it's not using clipboard to store those lines.

So is it possible?


You should yank the text to the * or + registers:

gg"*yG

Explanation:

  • gg to get the cursor to the first character of the file
  • "*y to start a yank command to the register * from the first line, until...
  • G to go the end of the file

  • Use:

    :%y+

    to yank all lines.

    Explanation:

  • % to refer the next command to work on all the lines
  • y to yank those lines
  • + to copy to the system clipboard
  • NB : In Windows, + and * are equivalent see this answer.


    on Mac

  • copy selected part: visually select text(type v or V in normal mode) and type :w !pbcopy

  • copy the whole file :%w !pbcopy

  • past from the clipboard :r !pbpaste

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

    上一篇: 如何在vi或vim中多次缩进单行?

    下一篇: 将所有行复制到剪贴板