开发者

in vim with xclip, yank to clipboard

I have vim 7.2 (-clipboard -xt开发者_Python百科erm_clipboard ...) in Ubuntu. You can see that it's not support clipboard. So I want to write little vim script which copies visual selected text into the clipboard using xclip tool.

You know xclip tool works like that:

echo 'hello' | xclip -selection clipboard      #it copies 'hello' into clipboard

And vim can run shell commands, so I want to copy visual selected text to where instead of 'hello', But I don't know how to combine xclip and vim. Can you help me to implement it.

Thanks for your time!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜