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


当前回答

对于一些国际键盘,您可能需要按“+空格获得a”。

所以在这种情况下,你必须按“空格+y”或“空格*y”

其他回答

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

sudo apt-get install vim-gnome

@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

我在我的.vimrc中写了一个简单的行来让复制工作。希望这能帮助到一些人。不幸的是,我的vim没有安装剪贴板支持,所以这些建议对我都不起作用。基本上,将这一行粘贴到你的.vimrc中:

map <C-c> y:e ~/clipsongzboard<CR>P:w !pbcopy<CR><CR>:bdelete!<CR>

如果你想了解详细信息,你可以在我的博客上阅读

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

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

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