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


当前回答

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

其他回答

Shift + Ctrl + C 如果你在Linux的图形模式,但首先你需要选择你需要复制什么。

在vimrc文件中,可以指定自动使用系统剪贴板进行复制和粘贴。

macOS和Windows设置:

set clipboard=unnamed

Linux set (vim 7.3.74+):

set clipboard=unnamedplus

注意:您可能需要使用最新版本的Vim才能工作。

http://vim.wikia.com/wiki/Accessing_the_system_clipboard

对于Mac OS X,在终端中:

运行vim——version | grep clipboard检查是否启用了剪贴板(使用+)

将下面的代码添加到.vimrc文件中

如果有(“剪贴板”) Set clipboard= named "复制到系统剪贴板 If has("unnamedplus") "X11支持 设置剪贴板+ = unnamedplus endif endif

重启终端和vim

参考:在Mac OS X上设置Vim到剪贴板

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).

在我的实例中,用鼠标高亮显示(单击和拖动)选择文本会导致vim进入可视模式。

在mac上,最简单的解决方案是使用fn +鼠标点击和拖动,以避免进入可视模式。

如果您希望在默认情况下避免这种行为,可以编辑vimrc