如何从(并复制到)系统的剪贴板制作vim粘贴?

时间:2022-09-12 23:05:29

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商店将文本复制到自己的剪贴板中。因此,我很难从网页复制一些文本并将其粘贴到当前的工作文件中。碰巧我必须打开gedit或手动输入它。

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

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

26 个解决方案

#1


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).

“*和”+寄存器用于系统的剪贴板(:帮助寄存器)。根据您的系统,他们可能会做不同的事情。例如,在不使用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. 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 <C-c> "*y in your ~/.vimrc so that you can visually select and press Ctrl+c to yank to your system's clipboard.

如果所有这些都超过你的头,尝试使用“* yy或”+ yy将一行复制到系统的剪贴板。假设您有适当的编译选项,那么一个或另一个应该可以工作。您可能希望将其重新映射到更方便的地方。例如,您可以将vnoremap “* 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. 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.

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

You also may want to have a look at the 'clipboard' option described at :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.

您还可以查看以下所述的“剪贴板”选项:help cb。在这种情况下,您可以:设置clipboard = unnamed或:set clipboard = unnamedplus以使所有yanking / deletion操作自动复制到系统剪贴板。在某些情况下,如果您将其他内容存储在剪贴板中,因为它会覆盖它,这可能会带来不便。

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.

要粘贴,您可以使用“+ p或”* p(同样,取决于您的系统和/或所需的选择),或者您可以将这些映射到其他内容。我明确地键入它们,但我经常发现自己处于插入模式。如果您处于插入模式,您仍然可以使用 *或 +将它们粘贴到适当的缩进处。请参阅:help i_CTRL-R_CTRL-P。

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 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). 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的粘贴选项(:帮助粘贴)。这使得vim进入一种特殊的“粘贴模式”,禁用其他几个选项,允许您使用终端仿真器或多路复用器熟悉的粘贴快捷方式轻松粘贴到vim中。只需输入:设置粘贴以启用它,粘贴您的内容,然后键入:set nopaste以禁用它。或者,您可以使用pastetoggle选项设置切换模式的键代码(:help pastetoggle)。我建议使用寄存器而不是这些选项,但如果它们仍然太可怕,那么当你完善你的vim印章时,这可能是一个方便的解决方法。

See :help clipboard for more detailed information.

请参阅:帮助剪贴板以获取更多详细信息

#2


You can copy into vim by gnome-terminal's shortcut for paste. Make the file in insert mode and use

您可以通过gnome-terminal的快捷方式复制到vim中进行粘贴。使文件处于插入模式并使用

Ctrl+Shift+v.

Remember beforehand to

请事先记住

 :set paste 

to avoid messing with the indentation.

避免弄乱压痕。

#3


Linux

On my Linux system, the + and * registers map to an X11 selection, which can be pasted with the middle mouse button. When :set clipboard=unnamed and :set clipboard=unnamedplus are used, then the registers map to the clipboard, and can be pasted with CTRL-V.

在我的Linux系统上,+和*寄存器映射到X11选择,可以使用鼠标中键粘贴。当: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

#4


For my that configuration works for copying and pasting

因为我的配置适用于复制和粘贴

" copy and pastevmap <C-c> "+yivmap <C-x> "+cvmap <C-v> c<ESC>"+pimap <C-v> <ESC>"+pa

#5


This would be the lines you need in your vimrc for this purpose:

这将是您在vimrc中为此目的所需的行:

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

#6


I believe that this question deserves a more objective answer.

我认为这个问题应该得到一个更客观的答案。

Entering Paste Mode

进入粘贴模式

  • ESC
  • :set paste
  • press i
  • SHIFT + Insert (with a text copied on your clipboard)
  • SHIFT +插入(在剪贴板上复制文本)


Leaving Paste Mode

离开粘贴模式

  • ESC
  • :set nopaste
  • press i

You pasted the text and you're able to type again.

您粘贴了文本,然后您可以再次键入。

#7


clipboard

There is a special register for storing this selection, it is the "*register. Nothing is put in here unless the information about what text isselected is about to change (e.g. with a left mouse click somewhere), or whenanother application wants to paste the selected text. Then the text is putin the "* register. For example, to cut a line and make it the currentselection/put it on the CLIPBOARD:

有一个特殊的寄存器用于存储这个选项,它是“*寄存器。除非有关所选文本的信息即将更改(例如,在某处单击鼠标左键),或者当另一个应用程序想要粘贴选中的文本。然后将文本放在“*寄存器中。例如,要剪切一条线并使其成为当前选择/将其放在CLIPBOARD上:

    "*dd

Similarly, when you want to paste a selection from another application, e.g.,by clicking the middle mouse button, the selection is put in the "* registerfirst, and then 'put' like any other register. For example, to put theselection (contents of the CLIPBOARD):

类似地,当您想要粘贴来自另一个应用程序的选择时,例如,通过单击鼠标中键,选择将被放入“* registerfirst,然后'put',就像任何其他寄存器一样。例如,要放置这些选择(内容)的CLIPBOARD):

    "*p

registers E354

> There are nine types of registers:                      > 1. The unnamed register ""> 2. 10 numbered registers "0 to "9> 3. The small delete register "-> 4. 26 named registers "a to "z or "A to "Z> 5. four read-only registers ":, "., "% and "#> 6. the expression register "=> 7. The selection and drop registers "*, "+ and "~ > 8. The black hole register "_> 9. Last search pattern register "/

Paste from clipboard

从剪贴板粘贴

1. Clipboard: Copy2. Vim insertmode, middle mouse key

Check for X11-clipboard support in terminal

检查终端中的X11剪贴板支持

When you like to run Vim in a terminal you need to look for a version of Vim that was compiled with clipboard support.Check for X11-clipboard support, from the console, type:

当你想在终端中运行Vim时,你需要寻找一个用剪贴板支持编译的Vim版本。检查X11-clipboard支持,从控制台输入:

% vim --version

If you see "+xterm_clipboard", you are good to go.

如果你看到“+ xterm_clipboard”,你很高兴。

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

The X server maintains three selections, called:

X服务器维护三个选项,称为:

PRIMARY, SECONDARY and CLIPBOARD

小学,中学和剪贴板

The PRIMARY selection is conventionally used to implement copying and pasting via the middle mouse button. The SECONDARY and CLIPBOARD selections are less frequently used by application programs.

PRIMARY选择通常用于通过鼠标中键实现复制和粘贴。应用程序不常使用SECONDARY和CLIPBOARD选项。

http://linux.die.net/man/1/xsel

#8


I tried the suggestions above and none of them worked in my environment. (Windows PuTTY clone over ssh)

我尝试了上面的建议,但没有一个在我的环境中工作。 (Windows PuTTY克隆ssh)

Some additional googling turned up:https://unix.stackexchange.com/questions/110684/copy-paste-into-sshd-vim-from-local-windows-clipboard

一些额外的谷歌搜索出现了:https://unix.stackexchange.com/questions/110684/copy-paste-into-sshd-vim-from-local-windows-clipboard

One of the comments suggested using SHIFT+INSERT which did the trick for pasting from my desktop's clipboard into Vim's buffer. Ctrl-C was already working to copy to the desktop's clipboard from Vim.

其中一条评论建议使用SHIFT + INSERT,它可以将我桌面的剪贴板粘贴到Vim的缓冲区中。 Ctrl-C已经在从Vim复制到桌面的剪贴板。

#9


Didn't have +clipboard so I came up with this alternative solution using xsel:

没有+剪贴板所以我想出了使用xsel的替代解决方案:

Add to your ~/.vimrc:

添加到〜/ .vimrc:

vnoremap <C-C> :w !xsel -b<CR><CR>

vnoremap :w!xsel -b

#10


A quick note for people whose vim installation does not support the * and + registers. It is not necessary to download a new vim installation to paste from the clipboard. Here is an alternative method:

对于vim安装不支持*和+寄存器的人员的快速说明。没有必要从剪贴板下载新的vim安装进行粘贴。这是另一种方法:

1) Install parcellite (a clipboard manager with a low memory footprint);

1)安装parcellite(内存占用少的剪贴板管理器);

2) In your .vimrc file, add the following:

2)在.vimrc文件中,添加以下内容:

command Clip r !parcellite -c

3) Restart vim.

3)重启vim。

Now when you type in :Clip as an ex command, the contents of the clipboard will be pasted in at the cursor. You can also map the new command to a function key so as to be able to do this with one keystroke.

现在当您输入:Clip作为ex命令时,剪贴板的内容将粘贴在光标处。您还可以将新命令映射到功能键,以便能够通过一次击键执行此操作。

#11


This works for me: Ctrl+Shift+V

这对我有用:Ctrl + Shift + V.

#12


Following on from Conner's answer, which was great, but C-R C-p + and C-R C-p * in insert mode is a bit inconvenient. Ditto "*p and "+p from command mode.

继Conner的回答之后,这很好,但插入模式下的C-R C-p +和C-R C-p *有点不方便。从命令模式同样“* p和”+ p。

a VIM guru suggested the following to map C-v to what C-r C-p + does.

一位VIM大师建议如下将C-v映射到C-r C-p +。

You could have :inoremap <C-v> <C-o>"+p for insert mode only

您可以:inoremap “+ p仅用于插入模式

if you really wanted to override blockwise visual mode (not recommended by him as visual mode is good) you could have map <C-v> "+p

如果你真的想要覆盖块状视觉模式(不推荐他作为视觉模式是好的)你可以有地图 “+ p

#13


If you are using vim in MAC OSX, unfortunately it comes with older verion, and not complied with clipboard options. Luckily, homebrew can easily solve this problem.

如果你在MAC OSX中使用vim,不幸的是它配备了较旧版本,并且没有符合剪贴板选项。幸运的是,自制软件可以轻松解决这个问题。

install vim:

brew install vim --with-lua --with-override-system-vim

brew install vim --with-lua --with-override-system-vim

install gui verion of vim:

安装vim的gui:

brew install macvim --with-lua --with-override-system-vim

brew install macvim --with-lua --with-override-system-vim

restart the terminal to take effect.

重启终端才能生效。


append the following line to ~/.vimrc
set clipboard=unnamed

将以下行追加到〜/ .vimrc set clipboard = unnamed

now you can copy the line in vim with yy and paste it system-wide.

现在你可以用yy复制vim中的行并在系统范围内粘贴它。

#14


On top of the setting :set clipboard=unnamed, you should use mvim -v which you can get with brew install macvim if you're using vim on Terminal.app on Mac OS X 10.9. Default vim does not support clipboard option.

在设置之上:设置clipboard = unnamed,你应该使用mvim -v,如果你在Mac OS X 10.9上的Terminal.app上使用vim,你可以使用brew install macvim。默认vim不支持剪贴板选项。

#15


It may also be worth mentioning, on OSX using Vim, you can select text with the mouse, Cmd-C to copy to OSX system clipboard, and the copied text will be available in the clipboard outside of Vim.

值得一提的是,在使用Vim的OSX上,您可以使用鼠标选择文本,Cmd-C复制到OSX系统剪贴板,复制的文本将在Vim之外的剪贴板中可用。

In other words, OSX treats it like it were a regular window, and this is where the much-maligned Apple "Command" button comes in handy.

换句话说,OSX将其视为常规窗口,这就是备受诟病的Apple“Command”按钮派上用场的地方。

B-30

#16


Based on @lis2 answer, I use a simpler configuration that will not force Insert mode at the end:

根据@ lis2的答案,我使用了一个更简单的配置,最后不会强制插入模式:

" Copy and pasteif has('clipboard') && !has('gui_running')  vnoremap <C-c> "+y  vnoremap <C-x> "+d  vnoremap <C-v> "+p  inoremap <C-v> <C-r><C-o>+endif

Mind that all these override default Vim mappings:

请注意,所有这些都覆盖默认的Vim映射:

  • v_CTRL-C: stop Visual mode
  • v_CTRL-C:停止可视模式

  • v_CTRL-X: subtract [count] from number
  • v_CTRL-X:从数字中减去[count]

  • v_CTRL-V: blockwise Visual mode
  • v_CTRL-V:逐块可视模式

  • i_CTRL-V: insert next non-digit literally, which is also mapped to i_CTRL-Q
  • i_CTRL-V:按字面插入下一个非数字,也映射到i_CTRL-Q

As an alternative, one can use keys inspired in the "yank", "delete" and "put" Vim verbs: <C-y>, <C-d> and <C-p> respectively. These would only override one default mapping:

作为替代方案,可以使用分别在“yank”,“delete”和“put”Vim动词中启发的键: , 。这些只会覆盖一个默认映射:

  • i_CTRL-P: backwards search keyword for completion
  • i_CTRL-P:向后搜索关键字以完成

#17


What you really need is EasyClip. It will do just that and so much more...

你真正需要的是EasyClip。它会做到这一点,还有更多......

#18


The simplest solution to this, that also works between different Linux machines through ssh is:

最简单的解决方案,也可以通过ssh在不同的Linux机器之间工作:

  1. Check whether vim supports X-11 clipboard: vim --version | grep clipboard. If it reports back -clipboard and -xterm_clipboard you should install either vim-gtk or vim-gnome (gvim on arch linux)

    检查vim是否支持X-11剪贴板:vim --version | grep剪贴板。如果它报告回-clipboard和-xterm_clipboard你应该安装vim-gtk或vim-gnome(gvim在arch linux上)

  2. Add the following lines to your .vimrc:

    将以下行添加到.vimrc:

set clipboard=unnamedplusset paste
  1. If you login on a different machine via ssh, use the option -Y: ssh -Y machine
  2. 如果您通过ssh登录其他计算机,请使用选项-Y:ssh -Y machine

Now copying and pasting should work exactly as expected on a single, and across different machines by only using y for yank and p for paste. NB modify .vimrc on all machines where you want to use this feature.

现在,复制和粘贴应该在单个和不同的机器上完全按预期工作,只需使用y表示yank,p表示粘贴。 NB在要使用此功能的所有计算机上修改.vimrc。

#19


With Vim 8+ on Linux or Mac, you can now simply use the OS' native paste (ctrl+shift+V on Linux, cmd+V on Mac). Do not press i for Insert Mode.

使用Linux或Mac上的Vim 8+,您现在可以简单地使用操作系统的本机粘贴(Linux上的ctrl + shift + V,Mac上的cmd + V)。请勿按i进入插入模式。

It will paste the contents of your OS clipboard, preserving the spaces and tabs without adding autoindenting. It's equivalent to the old :set paste, i, ctrl+shift+V, esc, :set nopaste method.

它将粘贴操作系统剪贴板的内容,保留空格和制表符,而不添加自动延迟。它相当于旧:设置粘贴,i,ctrl + shift + V,esc,:set nopaste方法。

You don't even need the +clipboard or +xterm_clipboard vim features installed anymore. This feature is called "bracketed paste". For more details, see Turning off auto indent when pasting text into vim

您甚至不需要安装+剪贴板或+ xterm_clipboard vim功能。此功能称为“括号粘贴”。有关更多详细信息,请参阅将文本粘贴到vim时关闭自动缩进

#20


When I use my Debian vim that is not integrated with Gnome (vim --version | grep clip # shows no clipboard support), I can copy to the clipboard after holding the Shift key and selecting the text with the mouse, just like with any other curses program. As I figured from a comment by @Conner, it's the terminal (gnome-terminal in my case) that turns off its mouse event reporting when it senses my Shift press. I guess curses-based programs can receive mouse events after sending a certain Escape sequence to the terminal.

当我使用未与Gnome集成的Debian vim时(vim --version | grep clip#显示没有剪贴板支持),我可以在按住Shift键并用鼠标选择文本后复制到剪贴板,就像任何其他诅咒计划。正如我从@Conner的评论中看到的那样,终端(在我的情况下是gnome-terminal)在感知到我的Shift按下时关闭了它的鼠标事件报告。我想基于curses的程序可以在将某个Escape序列发送到终端后接收鼠标事件。

#21


If you are on windows and you want to paste contents of system clipboard using p then type this command.

如果您在Windows上并且想要使用p粘贴系统剪贴板的内容,请键入此命令。

:set clipboard = unnamed

This solved my problem.

这解决了我的问题。

#22


There are two simple ways to do this. Make your file in insert mode and1) press the middle button (the scroll wheel) in your mouse, or2) Ctrl + Shift + V

有两种简单的方法可以做到这一点。使文件处于插入模式,1)按下鼠标中间的按钮(滚轮),或者按Ctrl + Shift + V

#23


For some international keyboards, you may need to press "+Space to get a ".

对于某些国际键盘,您可能需要按“+空格键才能获得”。

So in those case you would have to press "Space+y or "Space*y to copy.

因此,在这种情况下,您必须按“Space + y或”Space * y进行复制。

And "Space+p or " Space*p to paste.

并且“Space + p或”Space * p要粘贴。

#24


The other solutions are good if you want to change your vimrc, etc... However I wanted an simple way to copy from vim to my system keyboard. This is what I came up with.

如果你想改变你的vimrc等其他解决方案是好的...但是我想要一个简单的方法从vim复制到我的系统键盘。这就是我提出的。

  • Select the text you want to copy with visual mode v
  • 选择要使用可视模式v复制的文本

  • Press : (it will automatically expand to show :'<,'>)
  • 按:(它会自动展开显示:'<,'>)

  • Type y * or y + (depending on your system) to yank the selected text to the system clipboard
  • 键入y *或y +(取决于您的系统)将所选文本拖到系统剪贴板中

#25


If you are using a mouse first do

如果您先使用鼠标

 :set paste 

Then right click mouse and the contents in buffer will be pasted

然后右键单击鼠标,将粘贴缓冲区中的内容

#26


Since vim 8 right click enables visual mode by default. This prevents the "normal" copy & paste (call it a "defect by design" https://github.com/vim/vim/issues/1326).Fix it by doing:

由于vim 8右键单击默认启用可视模式。这可以防止“正常”复制和粘贴(称之为“设计缺陷”https://github.com/vim/vim/issues/1326)。修复它:

echo "set mouse-=a" >> ~/.vimrc .

echo“set mouse- = a”>>〜/ .vimrc。

Exit and restart vim.

退出并重新启动vim。

#1


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).

“*和”+寄存器用于系统的剪贴板(:帮助寄存器)。根据您的系统,他们可能会做不同的事情。例如,在不使用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. 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 <C-c> "*y in your ~/.vimrc so that you can visually select and press Ctrl+c to yank to your system's clipboard.

如果所有这些都超过你的头,尝试使用“* yy或”+ yy将一行复制到系统的剪贴板。假设您有适当的编译选项,那么一个或另一个应该可以工作。您可能希望将其重新映射到更方便的地方。例如,您可以将vnoremap “* 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. 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.

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

You also may want to have a look at the 'clipboard' option described at :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.

您还可以查看以下所述的“剪贴板”选项:help cb。在这种情况下,您可以:设置clipboard = unnamed或:set clipboard = unnamedplus以使所有yanking / deletion操作自动复制到系统剪贴板。在某些情况下,如果您将其他内容存储在剪贴板中,因为它会覆盖它,这可能会带来不便。

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.

要粘贴,您可以使用“+ p或”* p(同样,取决于您的系统和/或所需的选择),或者您可以将这些映射到其他内容。我明确地键入它们,但我经常发现自己处于插入模式。如果您处于插入模式,您仍然可以使用 *或 +将它们粘贴到适当的缩进处。请参阅:help i_CTRL-R_CTRL-P。

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 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). 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的粘贴选项(:帮助粘贴)。这使得vim进入一种特殊的“粘贴模式”,禁用其他几个选项,允许您使用终端仿真器或多路复用器熟悉的粘贴快捷方式轻松粘贴到vim中。只需输入:设置粘贴以启用它,粘贴您的内容,然后键入:set nopaste以禁用它。或者,您可以使用pastetoggle选项设置切换模式的键代码(:help pastetoggle)。我建议使用寄存器而不是这些选项,但如果它们仍然太可怕,那么当你完善你的vim印章时,这可能是一个方便的解决方法。

See :help clipboard for more detailed information.

请参阅:帮助剪贴板以获取更多详细信息

#2


You can copy into vim by gnome-terminal's shortcut for paste. Make the file in insert mode and use

您可以通过gnome-terminal的快捷方式复制到vim中进行粘贴。使文件处于插入模式并使用

Ctrl+Shift+v.

Remember beforehand to

请事先记住

 :set paste 

to avoid messing with the indentation.

避免弄乱压痕。

#3


Linux

On my Linux system, the + and * registers map to an X11 selection, which can be pasted with the middle mouse button. When :set clipboard=unnamed and :set clipboard=unnamedplus are used, then the registers map to the clipboard, and can be pasted with CTRL-V.

在我的Linux系统上,+和*寄存器映射到X11选择,可以使用鼠标中键粘贴。当: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

#4


For my that configuration works for copying and pasting

因为我的配置适用于复制和粘贴

" copy and pastevmap <C-c> "+yivmap <C-x> "+cvmap <C-v> c<ESC>"+pimap <C-v> <ESC>"+pa

#5


This would be the lines you need in your vimrc for this purpose:

这将是您在vimrc中为此目的所需的行:

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

#6


I believe that this question deserves a more objective answer.

我认为这个问题应该得到一个更客观的答案。

Entering Paste Mode

进入粘贴模式

  • ESC
  • :set paste
  • press i
  • SHIFT + Insert (with a text copied on your clipboard)
  • SHIFT +插入(在剪贴板上复制文本)


Leaving Paste Mode

离开粘贴模式

  • ESC
  • :set nopaste
  • press i

You pasted the text and you're able to type again.

您粘贴了文本,然后您可以再次键入。

#7


clipboard

There is a special register for storing this selection, it is the "*register. Nothing is put in here unless the information about what text isselected is about to change (e.g. with a left mouse click somewhere), or whenanother application wants to paste the selected text. Then the text is putin the "* register. For example, to cut a line and make it the currentselection/put it on the CLIPBOARD:

有一个特殊的寄存器用于存储这个选项,它是“*寄存器。除非有关所选文本的信息即将更改(例如,在某处单击鼠标左键),或者当另一个应用程序想要粘贴选中的文本。然后将文本放在“*寄存器中。例如,要剪切一条线并使其成为当前选择/将其放在CLIPBOARD上:

    "*dd

Similarly, when you want to paste a selection from another application, e.g.,by clicking the middle mouse button, the selection is put in the "* registerfirst, and then 'put' like any other register. For example, to put theselection (contents of the CLIPBOARD):

类似地,当您想要粘贴来自另一个应用程序的选择时,例如,通过单击鼠标中键,选择将被放入“* registerfirst,然后'put',就像任何其他寄存器一样。例如,要放置这些选择(内容)的CLIPBOARD):

    "*p

registers E354

> There are nine types of registers:                      > 1. The unnamed register ""> 2. 10 numbered registers "0 to "9> 3. The small delete register "-> 4. 26 named registers "a to "z or "A to "Z> 5. four read-only registers ":, "., "% and "#> 6. the expression register "=> 7. The selection and drop registers "*, "+ and "~ > 8. The black hole register "_> 9. Last search pattern register "/

Paste from clipboard

从剪贴板粘贴

1. Clipboard: Copy2. Vim insertmode, middle mouse key

Check for X11-clipboard support in terminal

检查终端中的X11剪贴板支持

When you like to run Vim in a terminal you need to look for a version of Vim that was compiled with clipboard support.Check for X11-clipboard support, from the console, type:

当你想在终端中运行Vim时,你需要寻找一个用剪贴板支持编译的Vim版本。检查X11-clipboard支持,从控制台输入:

% vim --version

If you see "+xterm_clipboard", you are good to go.

如果你看到“+ xterm_clipboard”,你很高兴。

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

The X server maintains three selections, called:

X服务器维护三个选项,称为:

PRIMARY, SECONDARY and CLIPBOARD

小学,中学和剪贴板

The PRIMARY selection is conventionally used to implement copying and pasting via the middle mouse button. The SECONDARY and CLIPBOARD selections are less frequently used by application programs.

PRIMARY选择通常用于通过鼠标中键实现复制和粘贴。应用程序不常使用SECONDARY和CLIPBOARD选项。

http://linux.die.net/man/1/xsel

#8


I tried the suggestions above and none of them worked in my environment. (Windows PuTTY clone over ssh)

我尝试了上面的建议,但没有一个在我的环境中工作。 (Windows PuTTY克隆ssh)

Some additional googling turned up:https://unix.stackexchange.com/questions/110684/copy-paste-into-sshd-vim-from-local-windows-clipboard

一些额外的谷歌搜索出现了:https://unix.stackexchange.com/questions/110684/copy-paste-into-sshd-vim-from-local-windows-clipboard

One of the comments suggested using SHIFT+INSERT which did the trick for pasting from my desktop's clipboard into Vim's buffer. Ctrl-C was already working to copy to the desktop's clipboard from Vim.

其中一条评论建议使用SHIFT + INSERT,它可以将我桌面的剪贴板粘贴到Vim的缓冲区中。 Ctrl-C已经在从Vim复制到桌面的剪贴板。

#9


Didn't have +clipboard so I came up with this alternative solution using xsel:

没有+剪贴板所以我想出了使用xsel的替代解决方案:

Add to your ~/.vimrc:

添加到〜/ .vimrc:

vnoremap <C-C> :w !xsel -b<CR><CR>

vnoremap :w!xsel -b

#10


A quick note for people whose vim installation does not support the * and + registers. It is not necessary to download a new vim installation to paste from the clipboard. Here is an alternative method:

对于vim安装不支持*和+寄存器的人员的快速说明。没有必要从剪贴板下载新的vim安装进行粘贴。这是另一种方法:

1) Install parcellite (a clipboard manager with a low memory footprint);

1)安装parcellite(内存占用少的剪贴板管理器);

2) In your .vimrc file, add the following:

2)在.vimrc文件中,添加以下内容:

command Clip r !parcellite -c

3) Restart vim.

3)重启vim。

Now when you type in :Clip as an ex command, the contents of the clipboard will be pasted in at the cursor. You can also map the new command to a function key so as to be able to do this with one keystroke.

现在当您输入:Clip作为ex命令时,剪贴板的内容将粘贴在光标处。您还可以将新命令映射到功能键,以便能够通过一次击键执行此操作。

#11


This works for me: Ctrl+Shift+V

这对我有用:Ctrl + Shift + V.

#12


Following on from Conner's answer, which was great, but C-R C-p + and C-R C-p * in insert mode is a bit inconvenient. Ditto "*p and "+p from command mode.

继Conner的回答之后,这很好,但插入模式下的C-R C-p +和C-R C-p *有点不方便。从命令模式同样“* p和”+ p。

a VIM guru suggested the following to map C-v to what C-r C-p + does.

一位VIM大师建议如下将C-v映射到C-r C-p +。

You could have :inoremap <C-v> <C-o>"+p for insert mode only

您可以:inoremap “+ p仅用于插入模式

if you really wanted to override blockwise visual mode (not recommended by him as visual mode is good) you could have map <C-v> "+p

如果你真的想要覆盖块状视觉模式(不推荐他作为视觉模式是好的)你可以有地图 “+ p

#13


If you are using vim in MAC OSX, unfortunately it comes with older verion, and not complied with clipboard options. Luckily, homebrew can easily solve this problem.

如果你在MAC OSX中使用vim,不幸的是它配备了较旧版本,并且没有符合剪贴板选项。幸运的是,自制软件可以轻松解决这个问题。

install vim:

brew install vim --with-lua --with-override-system-vim

brew install vim --with-lua --with-override-system-vim

install gui verion of vim:

安装vim的gui:

brew install macvim --with-lua --with-override-system-vim

brew install macvim --with-lua --with-override-system-vim

restart the terminal to take effect.

重启终端才能生效。


append the following line to ~/.vimrc
set clipboard=unnamed

将以下行追加到〜/ .vimrc set clipboard = unnamed

now you can copy the line in vim with yy and paste it system-wide.

现在你可以用yy复制vim中的行并在系统范围内粘贴它。

#14


On top of the setting :set clipboard=unnamed, you should use mvim -v which you can get with brew install macvim if you're using vim on Terminal.app on Mac OS X 10.9. Default vim does not support clipboard option.

在设置之上:设置clipboard = unnamed,你应该使用mvim -v,如果你在Mac OS X 10.9上的Terminal.app上使用vim,你可以使用brew install macvim。默认vim不支持剪贴板选项。

#15


It may also be worth mentioning, on OSX using Vim, you can select text with the mouse, Cmd-C to copy to OSX system clipboard, and the copied text will be available in the clipboard outside of Vim.

值得一提的是,在使用Vim的OSX上,您可以使用鼠标选择文本,Cmd-C复制到OSX系统剪贴板,复制的文本将在Vim之外的剪贴板中可用。

In other words, OSX treats it like it were a regular window, and this is where the much-maligned Apple "Command" button comes in handy.

换句话说,OSX将其视为常规窗口,这就是备受诟病的Apple“Command”按钮派上用场的地方。

B-30

#16


Based on @lis2 answer, I use a simpler configuration that will not force Insert mode at the end:

根据@ lis2的答案,我使用了一个更简单的配置,最后不会强制插入模式:

" Copy and pasteif has('clipboard') && !has('gui_running')  vnoremap <C-c> "+y  vnoremap <C-x> "+d  vnoremap <C-v> "+p  inoremap <C-v> <C-r><C-o>+endif

Mind that all these override default Vim mappings:

请注意,所有这些都覆盖默认的Vim映射:

  • v_CTRL-C: stop Visual mode
  • v_CTRL-C:停止可视模式

  • v_CTRL-X: subtract [count] from number
  • v_CTRL-X:从数字中减去[count]

  • v_CTRL-V: blockwise Visual mode
  • v_CTRL-V:逐块可视模式

  • i_CTRL-V: insert next non-digit literally, which is also mapped to i_CTRL-Q
  • i_CTRL-V:按字面插入下一个非数字,也映射到i_CTRL-Q

As an alternative, one can use keys inspired in the "yank", "delete" and "put" Vim verbs: <C-y>, <C-d> and <C-p> respectively. These would only override one default mapping:

作为替代方案,可以使用分别在“yank”,“delete”和“put”Vim动词中启发的键: , 。这些只会覆盖一个默认映射:

  • i_CTRL-P: backwards search keyword for completion
  • i_CTRL-P:向后搜索关键字以完成

#17


What you really need is EasyClip. It will do just that and so much more...

你真正需要的是EasyClip。它会做到这一点,还有更多......

#18


The simplest solution to this, that also works between different Linux machines through ssh is:

最简单的解决方案,也可以通过ssh在不同的Linux机器之间工作:

  1. Check whether vim supports X-11 clipboard: vim --version | grep clipboard. If it reports back -clipboard and -xterm_clipboard you should install either vim-gtk or vim-gnome (gvim on arch linux)

    检查vim是否支持X-11剪贴板:vim --version | grep剪贴板。如果它报告回-clipboard和-xterm_clipboard你应该安装vim-gtk或vim-gnome(gvim在arch linux上)

  2. Add the following lines to your .vimrc:

    将以下行添加到.vimrc:

set clipboard=unnamedplusset paste
  1. If you login on a different machine via ssh, use the option -Y: ssh -Y machine
  2. 如果您通过ssh登录其他计算机,请使用选项-Y:ssh -Y machine

Now copying and pasting should work exactly as expected on a single, and across different machines by only using y for yank and p for paste. NB modify .vimrc on all machines where you want to use this feature.

现在,复制和粘贴应该在单个和不同的机器上完全按预期工作,只需使用y表示yank,p表示粘贴。 NB在要使用此功能的所有计算机上修改.vimrc。

#19


With Vim 8+ on Linux or Mac, you can now simply use the OS' native paste (ctrl+shift+V on Linux, cmd+V on Mac). Do not press i for Insert Mode.

使用Linux或Mac上的Vim 8+,您现在可以简单地使用操作系统的本机粘贴(Linux上的ctrl + shift + V,Mac上的cmd + V)。请勿按i进入插入模式。

It will paste the contents of your OS clipboard, preserving the spaces and tabs without adding autoindenting. It's equivalent to the old :set paste, i, ctrl+shift+V, esc, :set nopaste method.

它将粘贴操作系统剪贴板的内容,保留空格和制表符,而不添加自动延迟。它相当于旧:设置粘贴,i,ctrl + shift + V,esc,:set nopaste方法。

You don't even need the +clipboard or +xterm_clipboard vim features installed anymore. This feature is called "bracketed paste". For more details, see Turning off auto indent when pasting text into vim

您甚至不需要安装+剪贴板或+ xterm_clipboard vim功能。此功能称为“括号粘贴”。有关更多详细信息,请参阅将文本粘贴到vim时关闭自动缩进

#20


When I use my Debian vim that is not integrated with Gnome (vim --version | grep clip # shows no clipboard support), I can copy to the clipboard after holding the Shift key and selecting the text with the mouse, just like with any other curses program. As I figured from a comment by @Conner, it's the terminal (gnome-terminal in my case) that turns off its mouse event reporting when it senses my Shift press. I guess curses-based programs can receive mouse events after sending a certain Escape sequence to the terminal.

当我使用未与Gnome集成的Debian vim时(vim --version | grep clip#显示没有剪贴板支持),我可以在按住Shift键并用鼠标选择文本后复制到剪贴板,就像任何其他诅咒计划。正如我从@Conner的评论中看到的那样,终端(在我的情况下是gnome-terminal)在感知到我的Shift按下时关闭了它的鼠标事件报告。我想基于curses的程序可以在将某个Escape序列发送到终端后接收鼠标事件。

#21


If you are on windows and you want to paste contents of system clipboard using p then type this command.

如果您在Windows上并且想要使用p粘贴系统剪贴板的内容,请键入此命令。

:set clipboard = unnamed

This solved my problem.

这解决了我的问题。

#22


There are two simple ways to do this. Make your file in insert mode and1) press the middle button (the scroll wheel) in your mouse, or2) Ctrl + Shift + V

有两种简单的方法可以做到这一点。使文件处于插入模式,1)按下鼠标中间的按钮(滚轮),或者按Ctrl + Shift + V

#23


For some international keyboards, you may need to press "+Space to get a ".

对于某些国际键盘,您可能需要按“+空格键才能获得”。

So in those case you would have to press "Space+y or "Space*y to copy.

因此,在这种情况下,您必须按“Space + y或”Space * y进行复制。

And "Space+p or " Space*p to paste.

并且“Space + p或”Space * p要粘贴。

#24


The other solutions are good if you want to change your vimrc, etc... However I wanted an simple way to copy from vim to my system keyboard. This is what I came up with.

如果你想改变你的vimrc等其他解决方案是好的...但是我想要一个简单的方法从vim复制到我的系统键盘。这就是我提出的。

  • Select the text you want to copy with visual mode v
  • 选择要使用可视模式v复制的文本

  • Press : (it will automatically expand to show :'<,'>)
  • 按:(它会自动展开显示:'<,'>)

  • Type y * or y + (depending on your system) to yank the selected text to the system clipboard
  • 键入y *或y +(取决于您的系统)将所选文本拖到系统剪贴板中

#25


If you are using a mouse first do

如果您先使用鼠标

 :set paste 

Then right click mouse and the contents in buffer will be pasted

然后右键单击鼠标,将粘贴缓冲区中的内容

#26


Since vim 8 right click enables visual mode by default. This prevents the "normal" copy & paste (call it a "defect by design" https://github.com/vim/vim/issues/1326).Fix it by doing:

由于vim 8右键单击默认启用可视模式。这可以防止“正常”复制和粘贴(称之为“设计缺陷”https://github.com/vim/vim/issues/1326)。修复它:

echo "set mouse-=a" >> ~/.vimrc .

echo“set mouse- = a”>>〜/ .vimrc。

Exit and restart vim.

退出并重新启动vim。