是否可以直接从Vim复制到剪贴板?yy只把东西复制到Vim的内部缓冲区。我想复制到操作系统的剪贴板。在Vim中有这样的命令吗?或者你只能在Vim中提取东西?
当前回答
总结一下,让新手更容易上手,
复制当前行,在命令模式输入:
"*yy
要复制整个文件/缓冲区,在命令模式下,首先通过gg转到开头,然后键入
"*yG
如上所述,这需要vim——version中的+clipboard,这表示支持剪贴板,-clipboard表示不支持。
其他回答
在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
在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)都没有预先安装在你的发行版上,你可以在回购中找到它们
@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.
我有问题,因为我的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”进行复制和粘贴。
我不能复制到剪贴板的系统中,因为我的~/中有这个。vimrc文件:
if has('mouse')
set mouse=a
endif
但如果你接下来添加这一行,它将允许你简单地按Ctrl+c将你所选择的任何东西放入剪贴板。
vmap <C-c> "+y
原始讨论和更多详细信息:启用set mouse=a从vim中复制文本