是否可以直接从Vim复制到剪贴板?yy只把东西复制到Vim的内部缓冲区。我想复制到操作系统的剪贴板。在Vim中有这样的命令吗?或者你只能在Vim中提取东西?


当前回答

我的解决方案是安装额外的vim,包括剪贴板选项:

sudo apt-get install vim-gnome

其他回答

我在我的.vimrc中写了一个简单的行来让复制工作。希望这能帮助到一些人。不幸的是,我的vim没有安装剪贴板支持,所以这些建议对我都不起作用。基本上,将这一行粘贴到你的.vimrc中:

map <C-c> y:e ~/clipsongzboard<CR>P:w !pbcopy<CR><CR>:bdelete!<CR>

如果你想了解详细信息,你可以在我的博客上阅读

@Jacob Dalton has mentioned this in a comment, but nobody seems to have mentioned in an answer that vim has to be compiled with clipboard support for any of the suggestions mentioned here to work. Mine wasn't configured that way on Mac OS X by default and I had to rebuild vim. Use this the command to find out whether you have it or not vim --version | grep 'clipboard'. +clipboard means you're good and the suggestions here will work for you, while -clipboard means you have to recompile and rebuild vim.

把设置剪贴板=未命名在你的vimrc。 选择你想要复制在视觉模式(按v进入)。 返回正常模式(按escape[esc]),按y复制。 如果你想从操作系统的剪贴板中粘贴一些东西,在Vim Normal模式下按p/ p。

如果您通过putty连接到Unix系统,那么按照以下步骤复制文件的内容

突出显示要复制的文本(您将能够逐页复制) 按ctrl+c(它将复制文本到剪贴板 粘贴任何外部编辑器 完成

我想补充一种方法来复制一行到剪贴板,并在函数上使用它。

这里有一个你在浏览器中打开URL的例子

let g:chrome_exe = 'C:/.../Google/Chrome/Application/chrome.exe'
function OpenURL()
    " copy the line and put it in the register *
    normal "*yy
    :execute "silent !start ".g:chrome_exe." ".getreg("*")
endfunction

map ,url :call OpenURL()<CR>