是否可以直接从Vim复制到剪贴板?yy只把东西复制到Vim的内部缓冲区。我想复制到操作系统的剪贴板。在Vim中有这样的命令吗?或者你只能在Vim中提取东西?
当前回答
In case you don't want to use any graphical interface for vim and you prefer to just stick with terminal emulator there may be a much simpler approach to this problem. Instead of using yank or anything like this, first take a look at documentation of terminal you use. I've been struggling with the same issue (trying to use +clipboard and xclip and so on) and in the end it turned out that in my terminal emulator it's enough to just press shift and select any text you want to copy. That's it. Quite simple and no need for messing with configuration. (I use urxvt by the way).
其他回答
我有问题,因为我的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”进行复制和粘贴。
我是一个Vim newby,但是,复制所有的文本到系统剪贴板(例如,如果你想把它粘贴到文字处理器或其他文本编辑器,如gedit,鼠标垫等…),在正常模式:
ggVGy
或者,更简单地说:
:%y
按照建议,我还安装了vim-gtk和put
设置剪贴板= unnamedplus
在我的。vimrc
一切都很正常
如果你只想复制文本的一部分,使用可视模式(v),选择你想要复制的文本,然后按y。
最后,我建议使用剪贴板程序,如Clipman(我最喜欢的)、Clipit、Parcellite或类似的程序。
(我在Debian Stretch Xfce中使用vim 8.0)
原谅我的英语!:-)
In case you don't want to use any graphical interface for vim and you prefer to just stick with terminal emulator there may be a much simpler approach to this problem. Instead of using yank or anything like this, first take a look at documentation of terminal you use. I've been struggling with the same issue (trying to use +clipboard and xclip and so on) and in the end it turned out that in my terminal emulator it's enough to just press shift and select any text you want to copy. That's it. Quite simple and no need for messing with configuration. (I use urxvt by the way).
在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)都没有预先安装在你的发行版上,你可以在回购中找到它们
如果您在旧版本的macOS中使用vim,不幸的是,附带版本的vim可能会使用剪贴板选项进行编译。幸运的是,自制程序可以很容易地解决这个问题。
安装vim: 安装vim 安装vim的gui版本: 酿造安装macvim 重启终端生效。 将下面的行追加到~/.vimrc 设置剪贴板=不知名的 现在,您可以用yy在vim中复制该行,并在系统范围内粘贴它。
更新方法:
多年来,我一直不满意固定剪贴板的方法。最大的缺点是它会搞乱你的剪贴板历史,即使当你使用x删除。这里有一个更好、更优雅的解决方案。
将vim的文本[range]复制到系统剪贴板中。(提示:先用v或v选择范围,然后输入冒号:激活Ex命令): (行范围):猛拉+ 例如,复制/删除第5-10行到系统剪贴板*寄存器使用: y: 5、10 * 将系统剪贴板中的内容新一行粘贴到vim中: :把+
注意:
如果您选择了一个单词范围,上述操作将不起作用。使用“*y”或“+y”将该可视化块保存到剪贴板。然而,这很难打字,我仍在考虑替代方案。 :help "*或:help *+获取更多信息 酿造信息vim将能够看到其他选项安装vim。目前它没有任何其他选择。