是否可以直接从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.
其他回答
对于一些国际键盘,您可能需要按“+空格获得a”。
所以在这种情况下,你必须按“空格+y”或“空格*y”
我有问题,因为我的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”进行复制和粘贴。
总结一下,让新手更容易上手,
复制当前行,在命令模式输入:
"*yy
要复制整个文件/缓冲区,在命令模式下,首先通过gg转到开头,然后键入
"*yG
如上所述,这需要vim——version中的+clipboard,这表示支持剪贴板,-clipboard表示不支持。
我在我的.vimrc中写了一个简单的行来让复制工作。希望这能帮助到一些人。不幸的是,我的vim没有安装剪贴板支持,所以这些建议对我都不起作用。基本上,将这一行粘贴到你的.vimrc中:
map <C-c> y:e ~/clipsongzboard<CR>P:w !pbcopy<CR><CR>:bdelete!<CR>
如果你想了解详细信息,你可以在我的博客上阅读
到目前为止,我在MacOsX上使用键盘快捷键已经为此挣扎了几个月。 我知道问题不是关于使用键盘短裤。但这可能会对有同样担忧的人有所帮助。
我发现如果你不勾选:
View ->允许鼠标报告
从终端菜单,您将能够复制到剪贴板使用
Command + c
一次。