是否可以直接从Vim复制到剪贴板?yy只把东西复制到Vim的内部缓冲区。我想复制到操作系统的剪贴板。在Vim中有这样的命令吗?或者你只能在Vim中提取东西?
当前回答
在我的实例中,用鼠标高亮显示(单击和拖动)选择文本会导致vim进入可视模式。
在mac上,最简单的解决方案是使用fn +鼠标点击和拖动,以避免进入可视模式。
如果您希望在默认情况下避免这种行为,可以编辑vimrc
其他回答
@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.
在我的情况下,使用鼠标和右键复制的帮助进行选择。
我不希望包括行号,所以我:在复制之前设置nonnumber。
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).
把设置剪贴板=未命名在你的vimrc。 选择你想要复制在视觉模式(按v进入)。 返回正常模式(按escape[esc]),按y复制。 如果你想从操作系统的剪贴板中粘贴一些东西,在Vim Normal模式下按p/ p。
我有问题,因为我的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”进行复制和粘贴。