in vim with xclip, yank to clipboard
Are you using your distribution-provided vim
? If so, the vim-tiny
, vim
, and vim-nox
packages have no clipboard support, but it does exist in vim-lesstiff
, vim-gtk
, and vim-gnome
.
If you insist on doing it your way,
:'<,'>w !xclip
would send the current selected lines to xclip, and
:call system('xclip', @0)
would send the last yank to xclip.
For me, Vim stopped being able to copy to the *
and +
registers over SSH, even though :echo has('clipboard')
was 1
, and other X programs still worked. The solution for me was to add a mapping that yanks (via a register) to xclip:
vnoremap <silent><Leader>y "yy <Bar> :call system('xclip', @y)<CR>
I select text, hit \y
and it arrives on my local clipboard. You can change which register it uses, e.g. c
for "clipboard" with "cy
and @c
.