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
This is what I do to yank the whole file:
ggVGy
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.
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??
Click the left mouse button, drag across the section you want to copy and release. The code automatically gets copied to clipboard.
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).
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.