是否可以直接从Vim复制到剪贴板?yy只把东西复制到Vim的内部缓冲区。我想复制到操作系统的剪贴板。在Vim中有这样的命令吗?或者你只能在Vim中提取东西?
当前回答
在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)都没有预先安装在你的发行版上,你可以在回购中找到它们
其他回答
关于这个问题,我看到了很多答案,而解决这个问题的方法是多种答案的结合。
我遵循的步骤,使vim复制到系统剪贴板
使用sudo apt卸载vim。(我太懒了,不知道如何用+剪贴板支持重新编译它。 使用sudo apt Install带有+clipboard的vim-athena安装另一个名为vim-athena的vim包。 添加到~/。Vimrc下面的行:set clipboard=unnamedplus。 通过进入命令模式并输入Source %来查找文件。 保存并退出。
注意: 我使用的是Ubuntu 20.04。
除了vim-gnome, Ubuntu 20.04的neovim默认也支持+y。
如果你不想安装一个新程序,你可以使用cat file.txt或gedit file.txt的惰性方法从那里复制。
@Jacob Dalton has mentioned this in a comment, but nobody seems to have mentioned in an answer that vim has to be compiled with clipboard support for any of the suggestions mentioned here to work. Mine wasn't configured that way on Mac OS X by default and I had to rebuild vim. Use this the command to find out whether you have it or not vim --version | grep 'clipboard'. +clipboard means you're good and the suggestions here will work for you, while -clipboard means you have to recompile and rebuild vim.
在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
如果您通过putty连接到Unix系统,那么按照以下步骤复制文件的内容
突出显示要复制的文本(您将能够逐页复制) 按ctrl+c(它将复制文本到剪贴板 粘贴任何外部编辑器 完成