Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
579 views
in Technique[技术] by (71.8m points)

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

Unlike other editors, vim stores copied text in its own clipboard.

(与其他编辑器不同,vim商店将文本复制到自己的剪贴板中。)

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.

(碰巧我必须打开gedit或手动输入它。)

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

(我可以在系统的剪贴板上进行vim粘贴吗?)

  ask by Santosh Kumar translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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-gtkvim-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以获取更多详细信息)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...