是否可以直接从Vim复制到剪贴板?yy只把东西复制到Vim的内部缓冲区。我想复制到操作系统的剪贴板。在Vim中有这样的命令吗?或者你只能在Vim中提取东西?
当前回答
@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.
其他回答
对于OSX,就像上面的10342个答案所表明的那样,你需要确保vim支持剪贴板功能,并且OSX预发布的那个不支持剪贴板,如果你运行 酿造安装vim它将工作。
除了运行vi仍然会让你运行预先发布的OSX版本,而不是你从brew安装的版本。
为了解决这个问题,我简单地将我的vim命令别名为酿造版本,而不是OSX的默认版本:
alias vim="/usr/local/Cellar/vim/8.0.1100_1/bin/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
到目前为止,我在MacOsX上使用键盘快捷键已经为此挣扎了几个月。 我知道问题不是关于使用键盘短裤。但这可能会对有同样担忧的人有所帮助。
我发现如果你不勾选:
View ->允许鼠标报告
从终端菜单,您将能够复制到剪贴板使用
Command + c
一次。
除了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.