windows 如何仅使用键盘从 bash 复制和粘贴到 vim,反之亦然?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8144065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:28:37  来源:igfitidea点击:

How do I copy and paste from bash to vim and vice-versa using only the keyboard?

windowslinuxbashvimputty

提问by Homer6

Using this command:

使用这个命令:

http://www.hypexr.org/bash_tutorial.php#vi

http://www.hypexr.org/bash_tutorial.php#vi

I'm able to use vim commands in the bash. But, what I'd like to do is copy and paste from that (bash) into vim and vice-versa.

我可以在 bash 中使用 vim 命令。但是,我想做的是从那个(bash)复制并粘贴到 vim 中,反之亦然。

I know there are other posts on here using the middle mouse button, but I use putty to connect to linux boxes, and the middle mouse performs a selection, just like the left click drag.

我知道这里有其他帖子使用鼠标中键,但是我使用putty连接到linux box,鼠标中键执行选择,就像左键单击拖动一样。

I'm not looking for something that will modify my windows clipboard. Selecting in vim is useful for transfering stuff to and from windows, but I'd like a solution that will work both through putty and using a direct terminal.

我不是在寻找可以修改我的 Windows 剪贴板的东西。在 vim 中进行选择对于向 Windows 传输内容和从 Windows 传输内容很有用,但我想要一个既可以通过腻子又可以使用直接终端的解决方案。

Thanks in advance...

提前致谢...

回答by Arcege

I use the copy&paste feature in screen. ctrl-[to enter copy mode and ctrl-]to paste. There are different buffers and the ability to dump to a file. It's pretty powerful. The default is to copy lines, but you can curtail by columns join display lines into a single copied line (and other options). And since you would likely already be in screen when you run vim, you would have the paste buffer available. I also have hooks to copy the buffer to/from the X clipboard.

我在screen. ctrl-[进入复制模式并ctrl-]粘贴。有不同的缓冲区和转储到文件的能力。它非常强大。默认是复制行,但您可以按列将显示行缩减为单个复制行(和其他选项)。并且由于您在运行 vim 时可能已经在屏幕中,因此您可以使用粘贴缓冲区。我也有将缓冲区复制到 X 剪贴板/从 X 剪贴板复制缓冲区的钩子。

回答by Balint

I don't know if that can help you, but I have installed a utility called xclip, which shares the X11 clipboard with VIM. I mainly use it to copy and paste between instances of VIM running in different terminal windows.

我不知道这是否可以帮助您,但我安装了一个名为 xclip 的实用程序,它与 VIM 共享 X11 剪贴板。我主要用它在不同终端窗口中运行的 VIM 实例之间进行复制和粘贴。

I typically use xclip with the following mappings, which keep a very similar behaviour to the usual yank and paste commands, but using the clipboard:

我通常使用带有以下映射的 xclip,它们与通常的 yank 和 paste 命令保持非常相似的行为,但使用剪贴板:

nmap `yy    :.w !xclip<CR><CR>
vmap `y     :w !xclip<CR><CR>
nmap `p     :.r!xclip -o<CR>
nmap `P     :.-r!xclip -o<CR>

回答by Kae Verens

You can copy from/to the clipboard in both vim and bash using ctrl + ins for copy, and shift + ins for paste.

您可以在 vim 和 bash 中使用ctrl +ins 进行复制,使用shift +ins 进行粘贴。

回答by ata

Use the *(or +in X Windows) registers to reference the system clipboard. Anything yanked-to or pasted-from those registers can be used to cooperate with other applications:

使用*(或+在 X Windows 中)寄存器来引用系统剪贴板。从这些寄存器中提取或粘贴的任何内容均可用于与其他应用程序合作:

Cut/Copy examples

剪切/复制示例

"*yy: copy current line to the system clipbard

"*yy: 复制当前行到系统剪贴板

gg"*yG: copy current file to the system clipbard

gg"*yG: 复制当前文件到系统剪贴板

"*dd: cut current line to the system clipbard

"*dd: 剪切当前行到系统剪贴板

etc, etc

等等等等



Paste examples

粘贴示例

"*p: paste the system clipbard

"*p: 粘贴系统剪贴板

Or in insert mode:

或者在插入模式下:

iCtrl+r*

iCtrl+r*

Or

或者

iCtrl+rCtrl+p*

iCtrl+ rCtrl+p*

(the last one pastes withouth formatting, useful to avoid those ugly pastes from the OS clipboard where each indented line appears more and more shifted)

(最后一个粘贴没有格式化,有助于避免操作系统剪贴板中的那些丑陋的粘贴,其中每个缩进的行看起来越来越移位)