The "*
and "+
registers are for the system's clipboard ( :help registers
).
("*
和"+
寄存器用于系统的剪贴板( :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). (例如,在不使用X11(如OSX或Windows)的系统上, "*
寄存器用于读取和写入系统剪贴板。在X11系统上,可以使用两个寄存器。有关详细信息,请参阅:help x11-selection
,但基本上"*
类似于X11的PRIMARY选择(通常用鼠标复制你选择的东西,用鼠标中键粘贴), "+
类似于X11的CLIPBOARD选择(这是剪贴板本身)。)
If all that went over your head, try using "*yy
or "+yy
to copy a line to your system's clipboard.
(如果所有这些都超过你的头,尝试使用"*yy
或"+yy
将一行复制到系统的剪贴板。)
Assuming you have the appropriate compile options, one or the other should work. (假设您有适当的编译选项,那么一个或另一个应该可以工作。)
You might like to remap this to something more convenient for you. (您可能希望将其重新映射到更方便的地方。)
For example, you could put vnoremap <Cc> "*y
in your ~/.vimrc so that you can visually select and press Ctrl + c to yank to your system's clipboard. (例如,您可以将vnoremap <Cc> "*y
放在?/ .vimrc中,这样您就可以直观地选择并按Ctrl + c来拖动到系统的剪贴板。)
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.
(请注意,如果:echo has('clipboard')
返回0,则从系统剪贴板复制/粘贴将不起作用。在这种情况下,vim不使用+clipboard
功能进行编译,您必须安装不同的版本或重新编译它。)
Some linux distros supply a minimal vim installation by default, but generally if you install the vim-gtk
or vim-gtk3
package you can get the extra features. (默认情况下,一些Linux发行版提供了最小的vim安装,但通常如果你安装了vim-gtk
或vim-gtk3
软件包,你就可以获得额外的功能。)
You also may want to have a look at the 'clipboard'
option described at :help cb
.
(您还可以查看以下所述的'clipboard'
选项: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. (在这种情况下,您可以:set clipboard=unnamed
或:set clipboard=unnamedplus
以使所有:set clipboard=unnamedplus
/ :set clipboard=unnamedplus
操作自动复制到系统剪贴板。)
This could be an inconvenience in some cases where you are storing something else in the clipboard as it will override it. (在某些情况下,如果您将其他内容存储在剪贴板中,因为它会覆盖它,这可能会带来不便。)
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.
(要粘贴,您可以使用"+p
或"*p
(同样,取决于您的系统和/或所需的选择),或者您可以将这些映射到其他内容。)
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 <Cr><Cp>*
or <Cr><Cp>+
. (如果您处于插入模式,您仍然可以使用<Cr><Cp>*
或<Cr><Cp>+
它们粘贴到适当的缩进处。)
See :help i_CTRL-R_CTRL-P
. (请参阅:help i_CTRL-R_CTRL-P
。)
It's also worth mentioning vim's paste
option ( :help paste
).
(还值得一提的是vim的paste
选项( :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 or multiplexer's familiar paste shortcut. (这使得vim进入一种特殊的“粘贴模式”,禁用其他几个选项,允许您使用终端仿真器或多路复用器熟悉的粘贴快捷方式轻松粘贴到vim中。)
Simply type :set paste
to enable it, paste your content and then type :set nopaste
to disable it. (只需输入:set paste
以启用它,粘贴您的内容,然后键入:set nopaste
以禁用它。)
Alternatively, you can use the pastetoggle
option to set a keycode that toggles the mode ( :help pastetoggle
). (或者,您可以使用pastetoggle
选项设置切换模式的键代码( :help pastetoggle
)。)
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. (我建议使用寄存器而不是这些选项,但如果它们仍然太可怕,那么当你完善你的vim印章时,这可能是一个方便的解决方法。)
See :help clipboard
for more detailed information.
(请参阅:help clipboard
以获取更多详细信息)