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


当前回答

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

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

其他回答

到目前为止,我在MacOsX上使用键盘快捷键已经为此挣扎了几个月。 我知道问题不是关于使用键盘短裤。但这可能会对有同样担忧的人有所帮助。

我发现如果你不勾选:

View ->允许鼠标报告

从终端菜单,您将能够复制到剪贴板使用

Command + c

一次。

如果你有xclip,一个简单的方法复制文本到剪贴板如下:

你想复制的Yank文本。(香草vim中的y命令) 输入:call system("xclip -selection clipboard", @")

:call system()执行终端命令。它有两个参数,第一个参数是命令,第二个参数是要向该命令输送什么。例如:echom系统("head -1", "Hello\nWorld")返回Hello(带一些填充)。Echom返回命令的输出,而call不返回。

xclip -selection剪贴板只是复制文本到系统剪贴板,而不是默认的X剪贴板,(通过鼠标中间按钮访问)。

@"返回最后一个被猛拉的文本。是默认寄存器,但您可以使用任何寄存器。要查看所有寄存器的内容,输入:registers。

我有问题,因为我的vim不支持剪贴板:

vim --version | grep clip
-clipboard       +insert_expand   +path_extra      +user_commands
+emacs_tags      -mouseshape      +startuptime     -xterm_clipboard

我安装了vim-gnome(支持剪贴板),然后再次检查:

vim --version | grep clipboard
+clipboard       +insert_expand   +path_extra      +user_commands
+emacs_tags      +mouseshape      +startuptime     +xterm_clipboard

现在我可以分别使用“+y”和“+p”进行复制和粘贴。

我在mac osx(10.15.3)和新的vim。我发现这太令人沮丧了,这里所有的答案都太复杂了,或者不适用于我的情况。我最终在两个方面得到了这个工作:

使用pbcopy的键映射:适用于mac附带的旧版本的vim。 将vmap ":w !pbcopy<CR><CR>添加到~/.vimrc中 现在您可以直观地选择并点击“(两个撇号)复制到剪贴板 安装新版本的vim,这样我就可以访问其他答案中最推荐的解决方案: 编译安装vim的别名vim=/usr/local/bin/vim(应该把这个添加到~/。Bashrc或同等语言) 现在您可以直观地选择并点击“+yy复制到剪贴板

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