Copy all the lines to clipboard

前端 未结 25 2229
礼貌的吻别
礼貌的吻别 2020-11-28 16:54

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

相关标签:
25条回答
  • 2020-11-28 17:30

    gVim:

    :set go=a
    

    ggVG

    See :help go-a:

    'a' Autoselect:  If present, then whenever VISUAL mode is started,
     or the Visual area extended, Vim tries to become the owner of
     the windowing system's global selection.  This means that the
     Visually highlighted text is available for pasting into other
     applications as well as into Vim itself.  When the Visual mode
     ends, possibly due to an operation on the text, or when an
     application wants to paste the selection, the highlighted text
     is automatically yanked into the "* selection register.
     Thus the selection is still available for pasting into other
     applications after the VISUAL mode has ended.
         If not present, then Vim won't become the owner of the
     windowing system's global selection unless explicitly told to
     by a yank or delete operation for the "* register.
     The same applies to the modeless selection.
    
    0 讨论(0)
  • 2020-11-28 17:31

    The clipboard is buffer +. To copy to clipboard, do "+y and [movement].

    So, gg"+yG will copy the whole file.

    Similarly, to paste from clipboard, "+p

    0 讨论(0)
  • 2020-11-28 17:31

    You can use a shortcur, like this one:

    noremap <F6> :%y+<CR>
    

    It means, when you push F6 in normald mode, it will copy the whole file, and add it to the clipboard. Or you just can type in normal mode :%y+ and then push Enter.

    0 讨论(0)
  • 2020-11-28 17:33

    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.

    0 讨论(0)
  • 2020-11-28 17:34

    Here's a map command to select all to the clipboard using CTRL+a:

    "
    " select all with control-a
    "
    nnoremap <C-a> ggmqvG"+y'q
    

    Add it to your .vimrc and you're good to go...

    0 讨论(0)
  • 2020-11-28 17:35

    On Ubuntu 12

    you might try to install the vim-gnome package:

    sudo apt-get install vim-gnome
    

    I tried it, because vim --version told me that it would have the flag xterm_clipboard disabled (indicated by - ), which is needed in order to use the clipboard functionality.

    -> installing the vim-gnome package on Ubuntu 12 also installed a console based version of vim, that has this option enabled (indicated by a + before the xterm_clipboard flag)

    On Arch Linux

    you may install vim-clipboard for the same reason.

    If you run neovim then you should install xclip (as explained by help clipboard-tool)

    0 讨论(0)
提交回复
热议问题