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
I tried a few of the commands that people have mentioned above. None worked. Then I got hold of the simplest of them all.
Step 1: vi <filename>
Step 2: Right click on the title bar of the Putty window
Step 3: Select "Clear scrollback" (to avoid copying the rest of your SSH session)
Step 4: Right click again and select "Copy all to clipboard".
Do copy the whole file inside the vim or its tabs
y G
then move to a tab and paste by
p
and to cut the whole file use
d G
You can use "cat" command to open file and use mouse to copy
I know ten years on this should be settled but the first two answers did not work for me so I kept digging. On a Redhat (remote server) - Windows 10 (local machine), if you cannot select the whole thing with a mouse, you are stuck because the usual copies do not work between the remote and the local machine clipboards.
So, to copy on the remote Linux and to paste on the local Windows, specify the primary buffer with the * and do a nice double yank
Use gg" * yy.
If your fingers default to CTRL-A CTRL-C
, then try the mappings from $VIMRUNTIME/mswin.vim
.
" CTRL-C and CTRL-Insert are Copy
vnoremap <C-C> "+y
" CTRL-A is Select all
noremap <C-A> gggH<C-O>G
inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
cnoremap <C-A> <C-C>gggH<C-O>G
onoremap <C-A> <C-C>gggH<C-O>G
snoremap <C-A> <C-C>gggH<C-O>G
xnoremap <C-A> <C-C>ggVG
I have them mapped to <Leader><C-a>
and <Leader><C-c>
.
(in reply to @rshdev, and to avoid having to recompile vim with +xterm_clipboard per @nelstrom in comments on OP)
there's a program called xclip that works like putclip on Ubuntu 11:
:%!xclip -sel clip
u
it's not installed by default. to install, use:
sudo apt-get install xclip