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


当前回答

在linux gnome (ubuntu, xubuntu等)安装vim-gnome,你将能够使用VISUAL选择,然后正常按Ctrl + C,用Ctrl + V粘贴到其他应用程序

sudo apt install vim-gnome

其他回答

In case you don't want to use any graphical interface for vim and you prefer to just stick with terminal emulator there may be a much simpler approach to this problem. Instead of using yank or anything like this, first take a look at documentation of terminal you use. I've been struggling with the same issue (trying to use +clipboard and xclip and so on) and in the end it turned out that in my terminal emulator it's enough to just press shift and select any text you want to copy. That's it. Quite simple and no need for messing with configuration. (I use urxvt by the way).

我不能复制到剪贴板的系统中,因为我的~/中有这个。vimrc文件:

 if has('mouse')
   set mouse=a
 endif

但如果你接下来添加这一行,它将允许你简单地按Ctrl+c将你所选择的任何东西放入剪贴板。

vmap <C-c> "+y

原始讨论和更多详细信息:启用set mouse=a从vim中复制文本

以上这些在我的windows笔记本电脑上都不起作用。

Ctrl+C可以用于复制。但我需要 Shift+插入到粘贴!

(一个很好的理由,总是有一个笔记本电脑,可以随时插入,而不需要按第二个键)

仅在ubuntu终端下的vim中,

在vim中按shift +鼠标拖动选择文本,然后在终端上按CTRL + shift + c

然后在其他编辑器上按CTRL + v

如果你正在使用GVim,你也可以设置guioptions+=a。这将触发自动复制到剪贴板的文本,您在视觉模式突出显示。 缺点:注意,高级剪贴板管理器(历史)将在这种情况下得到你所有的选择历史…