Copy all the lines to clipboard

2019-01-07 01:13发布

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?

标签: vim editor vi
22条回答
聊天终结者
2楼-- · 2019-01-07 01:42

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
查看更多
淡お忘
3楼-- · 2019-01-07 01:43

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.

查看更多
成全新的幸福
4楼-- · 2019-01-07 01:43

you can press gg to locate your curser to the start of the file,then press yG to copy all the content from the start to end(G located) to buffer.good luck!

查看更多
戒情不戒烟
5楼-- · 2019-01-07 01:44

:%y a Yanks all the content into vim's buffer, Pressing p in command mode will paste the yanked content after the line that your cursor is currently standing at.

查看更多
孤傲高冷的网名
6楼-- · 2019-01-07 01:47

I couldn't copy files using the answers above but I have putty and I found a workaround on Quora.

  1. Change settings of your PuTTY session, go to logging and change it to "printable characters". Set the log file
  2. Do a cat of the respective file
  3. Go to the file you set in step #1 and you will have your content in the log file.

Note: it copies all the printed characters of that session to the log file, so it will get big eventually. In that case, delete the log file and cat the target file so you get that particular file's content copied on your machine.

查看更多
家丑人穷心不美
7楼-- · 2019-01-07 01:48

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.

查看更多
登录 后发表回答