如何从(并复制到)系统的剪贴板制作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粘贴吗?


#1楼

参考:https://stackoom.com/question/mCvM/如何从-并复制到-系统的剪贴板制作vim粘贴


#2楼

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


#3楼

Linux Linux的

On my Linux system, the + and * registers map to an X11 selection, which can be pasted with the middle mouse button. 在我的Linux系统上, +*寄存器映射到X11选择,可以使用鼠标中键粘贴。 When :set clipboard=unnamed and :set clipboard=unnamedplus are used, then the registers map to the clipboard, and can be pasted with CTRL-V. :set clipboard=unnamed:set clipboard=unnamedplus使用时,寄存器映射到剪贴板,并可以用CTRL-V粘贴。

The specifics seem to be somewhat configuration and system dependent, so your mileage will definitely vary. 具体细节似乎与配置和系统有关,因此您的里程肯定会有所不同。 It should definitely get you pointed in the right direction, though. 不过,它肯定会让你指向正确的方向。

See Also 也可以看看

http://vim.wikia.com/wiki/Accessing_the_system_clipboard http://vim.wikia.com/wiki/Accessing_the_system_clipboard


#4楼

You can copy into vim by gnome-terminal's shortcut for paste. 您可以通过gnome-terminal的快捷方式复制到vim中进行粘贴。 Make the file in insert mode and use 使文件处于插入模式并使用

Ctrl + Shift + v . Ctrl + Shift + v

Remember beforehand to 请事先记住

 :set paste 

to avoid messing with the indentation. 避免弄乱压痕。


#5楼

This would be the lines you need in your vimrc for this purpose: 这将是您在vimrc中为此目的所需的行:

set clipboard+=unnamed  " use the clipboards of vim and win
set paste               " Paste from a windows or from vim
set go+=a               " Visual selection automatically copied to the clipboard

#6楼

For my that configuration works for copying and pasting 因为我的配置适用于复制和粘贴

" copy and paste
vmap <C-c> "+yi
vmap <C-x> "+c
vmap <C-v> c<ESC>"+p
imap <C-v> <ESC>"+pa
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值