gvim: Easy copying into system clipboard

后端 未结 5 451
庸人自扰
庸人自扰 2021-02-03 23:37

I am using gVim on Ubuntu 10.10. I want to copy (yank) text to the system clipboard, so that the copied text is available in other applications.

This works with \"

5条回答
  •  野性不改
    2021-02-03 23:54

    Most online solutions simply tell you to map y to "+y. But sometimes the issue is "+y doesn't even work. You do need to check what features your vim has been compiled with.

    Try the steps below:

    1. Open your terminal, run vim –-version | grep xterm_clipboard
    2. Check the sign before xterm_clipboard, if it’s a + (plus sign), go to step 4.
    3. If it’s a - (minus sign), run sudo apt-get install vim-gnome, then sudo update-alternatives –config vim, select vim.gnome in the list (You should use the proper command that corresponds to your system). Run command vim –-version | grep xterm_clipboard again, now you should be able to get + (plus sign).
    4. Check whether your system clipboard uses + (plus sign) or * (star sign) register of vim, this depends on the OS you're using, sometimes they’re equivalent. How to check? Just copy some random text, then open vim and type :reg, check which register shows the string you just copied. If it’s a + (plus sign), add set clipboard=unnamedplus to your .vimrc. If it’s a * (star sign), add set clipboard=unnamed.
    5. Test it out. Copy something inside vim, and then type :reg to check if the system clipboard has changed. If it does, your will get whatever is in that register when you paste outside of vim.

提交回复
热议问题