是否可以直接从Vim复制到剪贴板?yy只把东西复制到Vim的内部缓冲区。我想复制到操作系统的剪贴板。在Vim中有这样的命令吗?或者你只能在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 newby,但是,复制所有的文本到系统剪贴板(例如,如果你想把它粘贴到文字处理器或其他文本编辑器,如gedit,鼠标垫等…),在正常模式:

ggVGy

或者,更简单地说:

:%y

按照建议,我还安装了vim-gtk和put

设置剪贴板= unnamedplus

在我的。vimrc

一切都很正常

如果你只想复制文本的一部分,使用可视模式(v),选择你想要复制的文本,然后按y。

最后,我建议使用剪贴板程序,如Clipman(我最喜欢的)、Clipit、Parcellite或类似的程序。

(我在Debian Stretch Xfce中使用vim 8.0)

原谅我的英语!:-)

对于OSX,就像上面的10342个答案所表明的那样,你需要确保vim支持剪贴板功能,并且OSX预发布的那个不支持剪贴板,如果你运行 酿造安装vim它将工作。

除了运行vi仍然会让你运行预先发布的OSX版本,而不是你从brew安装的版本。

为了解决这个问题,我简单地将我的vim命令别名为酿造版本,而不是OSX的默认版本:

alias vim="/usr/local/Cellar/vim/8.0.1100_1/bin/vim"

现在我是金的

我已经使用这些很多年了:

nnoremap Y "+y
vnoremap Y "+y
nnoremap yY ^"+y$

你现在可以只使用大写Y复制到剪贴板,小写Y不会受到影响,例如通过set clipboard= named,所以你仍然可以选择拷贝是否会到剪贴板。

在ubuntu 21.04, vim 8.2上测试。

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

sudo apt-get 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).