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


当前回答

使用寄存器“+”复制到系统剪贴板(即。+y而不是y)。

同样,您可以从“+”粘贴从系统剪贴板(即。"+p而不是p)。

其他回答

对于Mac OS X,在终端中:

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

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

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

重启终端和vim

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

除了vim-gnome, Ubuntu 20.04的neovim默认也支持+y。

如果你不想安装一个新程序,你可以使用cat file.txt或gedit file.txt的惰性方法从那里复制。

关于这个问题,我看到了很多答案,而解决这个问题的方法是多种答案的结合。

我遵循的步骤,使vim复制到系统剪贴板

使用sudo apt卸载vim。(我太懒了,不知道如何用+剪贴板支持重新编译它。 使用sudo apt Install带有+clipboard的vim-athena安装另一个名为vim-athena的vim包。 添加到~/。Vimrc下面的行:set clipboard=unnamedplus。 通过进入命令模式并输入Source %来查找文件。 保存并退出。

注意: 我使用的是Ubuntu 20.04。

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文件中,可以指定自动使用系统剪贴板进行复制和粘贴。

macOS和Windows设置:

set clipboard=unnamed

Linux set (vim 7.3.74+):

set clipboard=unnamedplus

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

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