简体   繁体   English

在VIM中获取突出显示的副本并粘贴

[英]Getting highlight copy and paste in VIM

I'm trying to make the switch to VIM, but there's one feature I'm really lacking and that's the highlight copy - pasting. 我正在尝试切换到VIM,但是我确实缺少一个功能,这就是最重要的功能-粘贴。 Additionally, I am really lost with the "p" and "y" commands, I can't seem to copy or paste anything properly. 另外,我真的对“ p”和“ y”命令迷失了,我似乎无法正确地复制或粘贴任何内容。 I've set "clipboard=unnamedplus" to use the OS clipboard. 我已将“ clipboard = unnamedplus”设置为使用操作系统剪贴板。 Can you give me some pointers, or possibly a solution to my problems. 您能给我一些指导,还是解决我的问题? It'd be nice if I could Ctrl+C / Ctrl+V things and be able to copy highlighted text to my clipboard and paste from my clipboard. 如果我可以Ctrl + C / Ctrl + V并能够将突出显示的文本复制到剪贴板并从剪贴板粘贴,那就太好了。

Thanks in advance. 提前致谢。

By default, Vim yanks text and stores it in the " register; after yanking, you can see it by typing the :reg command. 默认情况下,Vim拉动文本并将其存储在"寄存器中;拉动之后,您可以通过键入:reg命令来查看文本。

However, you can control which register you want to yank or paste. 但是,您可以控制要拉取或粘贴的寄存器。 For example, "aY yanks/copies the current line into register a , "cp puts/pastes the content from register c . 例如, "aY将当前行猛拉/复制到寄存器a"cp从寄存器c放入/粘贴内容。

In Vim you have more than one "clipboard", you can "copy" many things in different "clipboards" and choose the right one to paste from. 在Vim中,您有多个“剪贴板”,您可以“复制”不同“剪贴板”中的许多内容,然后选择合适的内容进行粘贴。 It is Vim's great advantage, isn't it? 这是Vim的一大优势,不是吗?

If you want to use ctrl-c to copy selected text to system clipboard, you could: 如果要使用ctrl-c将选定的文本复制到系统剪贴板,则可以:

"easier copy/paste to/from clipboard
vnoremap <C-C> "+y
nnoremap <Leader>p "+P

But I wouldn't use CV to paste, as it is already assigned to the blockwise selection feature. 但是我不会使用CV粘贴,因为它已经分配给逐块选择功能。

To correctly paste from outside of terminal (possibly multiple indented lines of code) into Vim, add this to your ~/.vimrc : 要从终端外部(可能是多行缩进的代码)正确地粘贴到Vim中,请将其添加到您的~/.vimrc

set pastetoggle=<F2>

Then press F2, go to insert mode (you should see -- INSERT (paste) -- ) and Ctrl+shift+v to paste. 然后按F2键,进入插入模式(您应该看到-- INSERT (paste) -- ),然后Ctrl+shift+v进行粘贴。 Then again F2 to quit insert mode. 然后再次F2退出插入模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM