Copy all the lines to clipboard

前端 未结 25 2225
礼貌的吻别
礼貌的吻别 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:23

    This is what I do to yank the whole file:

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

    I have created a function to perform this action, place it on your ~/.vimrc.

    fun! CopyBufferToClipboard()
        %y+
    endfun
    nnoremap <Leader>y :call CopyBufferToClipboard()<CR>
    command! -nargs=0 CopyFile :call CopyBufferToClipboard()
    

    OBS: If you are using neovim you also need some clipboard manager like xclip. for more information type in neovim :h checkhealth

    It is also important to mention that not always a simple y will copy to the clipboard, in order to make every copy feed + wich is "Clipboard Register" try to set: :set clipboard=unnamed,unnamedplus. For mor information see: :h unnamed.

    Here more information on vim wikia.

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

    There wasn't a concept of "clipboard" in Bill Joy's vi so I don't think there is a built-in way to do it.

    gVim's automatic copy-anything-highlighted-to-the-clipboard feature is easiest or use an external program via :!

    For Cygwin's vim I use

    :%!putclip
    u
    

    Maybe Ubuntu has a CLI app like putclip??

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

    Click the left mouse button, drag across the section you want to copy and release. The code automatically gets copied to clipboard.

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

    I have added the following line to my .vimrc

    nnoremap <F5> :%y+<CR>
    

    This allows me to copy all text in Vim to the clipboard by pressing F5 (in command mode).

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

    Another easy way to copy the entire file if you're having problems using VI, is just by typing "cat filename". It will echo the file to screen and then you can just scroll up and down and copy/paste.

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