是否可以直接从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).

其他回答

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

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

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

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

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

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

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

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

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

现在我是金的

Ubuntu - 2018年7月

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

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

您还必须确保编译的vim支持剪贴板。试一试:

vim --version | grep .xterm_clipboard -o 

如果它是-xterm_clipboard(一个负号前缀),则不支持。

下面是一些使用支持剪贴板的vim工作版本进行交换的说明。

$ sudo apt-get purge vim 
$ sudo apt-get autoremove (removes any extraneous vim dependency packages from system) 
$ sudo apt-get install vim-gnome (or `sudo apt-get install vim-gtk3` for newer Ubuntu versions) 

再次检查vim——version | grep .xterm_clipboard -o,您可以确认剪贴板现在是可用的(即。+ xterm_clipboard)

我是一个Vim newby,但是,复制所有的文本到系统剪贴板(例如,如果你想把它粘贴到文字处理器或其他文本编辑器,如gedit,鼠标垫等…),在正常模式:

ggVGy

或者,更简单地说:

:%y

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

设置剪贴板= unnamedplus

在我的。vimrc

一切都很正常

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

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

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

原谅我的英语!:-)