如何从(并复制到)系统的剪贴板粘贴 vim? [英] How to make vim paste from (and copy to) system's clipboard?

查看:47
本文介绍了如何从(并复制到)系统的剪贴板粘贴 vim?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与其他编辑器不同,vim 将复制的文本存储在自己的剪贴板中.因此,我很难从网页中复制一些文本并将其粘贴到当前工作文件中.碰巧我必须打开 gedit 或手动输入.

Unlike other editors, vim stores copied text in its own clipboard. So, it's very hard for me to copy some text from a webpage and paste it into the current working file. It so happens I have to either open gedit or type it manually.

我可以在系统剪贴板中粘贴 vim 吗?

Can I make vim paste from and to the system's clipboard?

推荐答案

"*"+ 寄存器用于系统的剪贴板 (:帮助注册).根据您的系统,它们可能会做不同的事情.例如,在 OSX 或 Windows 等不使用 X11 的系统上,"* 寄存器用于读取和写入系统剪贴板.在 X11 系统上,两个寄存器都可以使用.有关更多详细信息,请参阅 :help x11-selection,但基本上 "* 类似于 X11 的 _PRIMARY_ 选择(通常复制您选择的内容)使用鼠标并使用鼠标中键粘贴)和 "+ 类似于 X11 的 _CLIPBOARD_ 选择(这是正确的剪贴板).

The "* and "+ registers are for the system's clipboard (:help registers). Depending on your system, they may do different things. For instance, on systems that don't use X11 like OSX or Windows, the "* register is used to read and write to the system clipboard. On X11 systems both registers can be used. See :help x11-selection for more details, but basically the "* is analogous to X11's _PRIMARY_ selection (which usually copies things you select with the mouse and pastes with the middle mouse button) and "+ is analogous to X11's _CLIPBOARD_ selection (which is the clipboard proper).

如果这一切都超出您的想象,请尝试使用 "*yy"+yy 将一行复制到系统的剪贴板.假设您有适当的编译选项,其中一个应该可以工作.

If all that went over your head, try using "*yy or "+yy to copy a line to your system's clipboard. Assuming you have the appropriate compile options, one or the other should work.

您可能希望将其重新映射为对您更方便的内容.例如,您可以将 vnoremap <C-c>"*y 在您的 ~/.vimrc 中,以便您可以直观地选择并按 Ctrl+c 猛拉到您的系统的剪贴板.

You might like to remap this to something more convenient for you. For example, you could put vnoremap <C-c> "*y in your ~/.vimrc so that you can visually select and press Ctrl+c to yank to your system's clipboard.

请注意,如果 :echo has('clipboard') 返回 0,则从系统剪贴板复制/粘贴将不起作用.在这种情况下,vim 没有使用 +clipboard 功能编译,您必须安装不同的版本或重新编译它.一些 Linux 发行版默认提供最小的 vim 安装,但如果你安装 vim-gtkvim-gtk3,你可以获得额外的尽管如此.

Be aware that copying/pasting from the system clipboard will not work if :echo has('clipboard') returns 0. In this case, vim is not compiled with the +clipboard feature and you'll have to install a different version or recompile it. Some linux distros supply a minimal vim installation by default, but if you install the vim-gtk or vim-gtk3 package you can get the extra features nonetheless.

您可能还想查看 :help cb 中描述的 'clipboard' 选项.在这种情况下,您可以 :set clipboard=unnamed:set clipboard=unnamedplus 使所有 yanking/deleting 操作自动复制到系统剪贴板.在某些情况下,这可能会给您带来不便,因为它会覆盖剪贴板中的其他内容.

You also may want to have a look at the 'clipboard' option described in :help cb. In this case you can :set clipboard=unnamed or :set clipboard=unnamedplus to make all yanking/deleting operations automatically copy to the system clipboard. This could be an inconvenience in some cases where you are storing something else in the clipboard as it will override it.

要粘贴,您可以使用 "+p"*p(同样,取决于您的系统和/或所需的选择),或者您可以将它们映射到别的东西.我明确地输入它们,但我经常发现自己处于插入模式.如果您处于插入模式,您仍然可以使用 <C-r><C-p>*<C-r><C 以适当的缩进粘贴它们-p>+.参见:help i_CTRL-R_CTRL-P.

To paste you can use "+p or "*p (again, depending on your system and/or desired selection) or you can map these to something else. I type them explicitly, but I often find myself in insert mode. If you're in insert mode you can still paste them with proper indentation by using <C-r><C-p>* or <C-r><C-p>+. See :help i_CTRL-R_CTRL-P.

还值得一提的是vim的paste选项(:help paste).这会将 vim 置于一种特殊的粘贴模式",该模式禁用了其他几个选项,允许您使用终端模拟器或多路复用器熟悉的粘贴快捷方式轻松粘贴到 vim 中.(只需输入 :set paste 以启用它,粘贴您的内容,然后输入 :set nopaste 以禁用它.)或者,您可以使用 pastetoggle 选项来设置切换模式的键码(:help pastetoggle).

It's also worth mentioning vim's paste option (:help paste). This puts vim into a special "paste mode" that disables several other options, allowing you to easily paste into vim using your terminal emulator's or multiplexer's familiar paste shortcut. (Simply type :set paste to enable it, paste your content and then type :set nopaste to disable it.) Alternatively, you can use the pastetoggle option to set a keycode that toggles the mode (:help pastetoggle).

我建议使用寄存器而不是这些选项,但如果它们仍然太可怕,那么在您完善 vim 排版时,这可能是一个方便的解决方法.

I recommend using registers instead of these options, but if they are still too scary, this can be a convenient workaround while you're perfecting your vim chops.

查看 :help clipboard 了解更多详细信息.

See :help clipboard for more detailed information.

这篇关于如何从(并复制到)系统的剪贴板粘贴 vim?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆