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


当前回答

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

在Mac OSX上

复制所选部分:可视选择文本(正常输入v或v) 模式)和类型:w !pbcopy 复制整个文件:%w !pbcopy 从剪贴板粘贴:r !pbpaste

在大多数Linux发行版上,你可以替换:

用xclip -i -sel c或xsel -i -b拷贝上面的内容 使用xclip -o -sel -c或xsel -o -b进行Pbpaste 注意:如果这些工具(xsel和xclip)都没有预先安装在你的发行版上,你可以在回购中找到它们

在我的情况下,使用鼠标和右键复制的帮助进行选择。

我不希望包括行号,所以我:在复制之前设置nonnumber。

这个问题已经有很多答案了。我在添加我的方法,我觉得很快。

快速地,你可以按V (Shift + V)到激活可视模式。在可见模式下,可以使用j和k选择要复制的文本。选择后使用

"*y

现在,选定的文本被复制到剪贴板。

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

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