简体   繁体   English

在 Windows 上的 Ubuntu 上复制粘贴到 Bash 中

[英]Copy Paste in Bash on Ubuntu on Windows

How to execute a copy paste operation from Windows 10 to the Bash on Ubuntu on Windows environment?如何在 Windows 环境下执行从 Windows 10 到 Bash on Ubuntu 的复制粘贴操作?

I tried the following:我尝试了以下方法:

  • ctrl + shift + v ctrl + shift + v
  • right click to paste右键粘贴

Any suggestions?有什么建议?

Update 2019/04/16: It seems copy/paste is now officially supported in Windows build >= 17643. Take a look at Rich Turner's answer . 2019 年 4 月 16 日更新: Windows build >= 17643 现在似乎正式支持复制/粘贴。看看Rich Turner 的回答 This can be enabled through the same settings menu described below by clicking the checkbox next to "Use Ctrl+Shift+C/V as Copy/Paste".这可以通过下面描述的相同设置菜单启用,方法是单击“使用 Ctrl+Shift+C/V 作为复制/粘贴”旁边的复选框。


Another solution would be to enable "QuickEdit Mode" and then you can paste by right-clicking in the terminal.另一种解决方案是启用“快速编辑模式”,然后您可以通过右键单击终端进行粘贴。

To enable QuickEdit Mode, right-click on the toolbar (or simply click on the icon in the upper left corner), select Properties, and in the Options tab, click the checkbox next to QuickEdit Mode.要启用快速编辑模式,请右键单击工具栏(或只需单击左上角的图标),选择属性,然后在选项选项卡中,单击快速编辑模式旁边的复选框。

With this mode enabled, you can also copy text in the terminal by clicking and dragging.启用此模式后,您还可以通过单击和拖动来复制终端中的文本。 Once a selection is made, you can press Enter or right-click to copy.做出选择后,您可以按 Enter 或右键单击进行复制。

To get right-click to paste to work:右键单击以粘贴工作:

  • Right-click on the title bar > Properties右键单击标题栏 > 属性
  • Options tab > Edit options > enable QuickEdit Mode选项选项卡 > 编辑选项 > 启用QuickEdit Mode

在此处输入图片说明

Ok, it's developed finally and now you are able to use Ctrl + Shift + C / V to Copy/Paste as of Windows 10 Insider build #17643.好的,它终于开发出来了,现在您可以使用Ctrl + Shift + C / V来复制/粘贴 Windows 10 Insider build #17643。

You'll need to enable the "Use Ctrl+Shift+C/V as Copy/Paste" option in the Console "Options" properties page:您需要在控制台“选项”属性页面中启用“使用 Ctrl+Shift+C/V 作为复制/粘贴”选项:

在此处输入图片说明

referenced in blogs.msdn.microsoft.com/blogs.msdn.microsoft.com/ 中引用

At long last, we're excited to announce that we FINALLY implemented copy and paste support for Linux/WSL instances in Windows Console via CTRL + SHIFT + [ C |最后,我们很高兴地宣布,我们最终通过CTRL + SHIFT + [ C | ] 在 Windows 控制台中实现了对 Linux/WSL 实例的复制和粘贴支持。 V ]! V]!

You can enable/disable this feature in case you find a keyboard collision with a command-line app, but this should start working when you install and run any Win10 builds >= 17643. Select "Properties" from the menu to access the following dialog box.如果您发现与命令行应用程序发生键盘冲突,您可以启用/禁用此功能,但这应该会在您安装和运行任何 Win10 版本 >= 17643 时开始工作。从菜单中选择“属性”以访问以下对话框盒子。

显示 CTRL + SHIFT + C/V 选项的新控制台属性

Thanks for your patience while we re-engineered Console's internals to allow this feature to work :)感谢您在我们重新设计 Console 的内部结构以允许此功能运行时的耐心等待 :)

您可以使用 AutoHotkey(第三方应用程序),下面的命令适用于纯字母数字文本,但是其他一些字符如=^"%#!在控制台中输入错误,如 bash 或 cmd。(在任何非控制台窗口中,此命令都有效所有字符都很好。)

^+v::SendRaw %clipboard%

从标题栏的上下文菜单中编辑/粘贴(直到他们修复控制键快捷键)

As others have said, there is now an option for Ctrl+Shf+V for paste in Windows 10 Insider build #17643.正如其他人所说,现在有一个Ctrl+Shf+V选项可以粘贴到 Windows 10 Insider build #17643 中。

Unfortunately this isn't in my muscle memory and as a user of TTY terminals I'd like to use Shf+Ins as I do on all the Linux boxes I connect to.不幸的是,这不是我的肌肉记忆,作为 TTY 终端的用户,我Shf+Ins在我连接的所有 Linux 机器上一样使用Shf+Ins

This is possible on Windows 10 if you install ConEmu which wraps the terminal in a new GUI and allows Shf+Ins for paste.如果您安装ConEmu ,它将终端包装在新的 GUI 中并允许Shf+Ins进行粘贴,那么这在 Windows 10 上是可能的。 It also allows you to tweak the behaviour in the Properties.它还允许您调整属性中的行为。

The Console looks like this:控制台看起来像这样: ConEmu 控制台

Copy options:复制选项: ConEmu 复制属性

Paste options:粘贴选项: ConEmu Paste 属性

Shf+Ins works out of the box. Shf+Ins开箱即用。 I can't remember if you need to configure bash as one of the shells it uses but if you do, here is the task properties to add it:我不记得您是否需要将 bash 配置为它使用的 shell 之一,但是如果您这样做了,这里是添加它的任务属性: ConEmu Bash 任务属性

Also allows tabbed Consoles (including different types, cmd.exe , powershell etc).还允许选项卡式控制台(包括不同类型、 cmd.exepowershell等)。 I've been using this since early Windows 7 and in those days it made the command line on Windows usable!我从早期的 Windows 7 开始就一直在使用它,在那些日子里,它使 Windows 上的命令行可用!

Like it has been written before:就像之前写过的:

  • Right Click on Bash on Ubuntu on Windows Icon if you have it on a Task Bar Shortcut Icon如果您在任务栏快捷方式图标上有它,请右键单击 Windows 图标上的 Ubuntu 上的 Bash
  • Click on Properties点击属性
  • Select Options Tab on the Properties Window在属性窗口中选择选项选项卡
  • Check the QuickEditMode option检查 QuickEditMode 选项
  • Click Apply点击应用

Now you are able to open a new Bash Terminal and just use Right-Click to paste现在您可以打开一个新的 Bash 终端并使用右键单击粘贴

In order to be able to copy from Terminal, Just use CTRL+M and this will enable you to select and copy selected Text.为了能够从终端复制,只需使用 CTRL+M,这将使您能够选择和复制选定的文本。

For pasting into Vim in the terminal (bash on ubuntu on windows):在终端中粘贴到 Vim(在 Windows 上的 ubuntu 上使用 bash):

export DISPLAY=localhost:0.0

Not sure how to copy from Vim though :-(不知道如何从 Vim 复制 :-(

Alternate solution over here, my windows home version Windows Subsystem Linux terminal doesn't have the property to use Shift+Ctrl (C|V)此处的替代解决方案,我的 Windows 家庭版 Windows 子系统 Linux 终端没有使用 Shift+Ctrl (C|V) 的属性

Use an actual linux terminal使用实际的 linux 终端![在此处输入图片说明] 1 ] 1

  • Install an X-server in Windows (like X-Ming)在 Windows 中安装 X 服务器(如 X-Ming)
  • sudo apt install <your_favorite_terminal>
  • export DISPLAY=:0
  • fire your terminal app, I tested with xfce4-terminal and gnome-terminal启动你的终端应用程序,我用 xfce4-terminal 和 gnome-terminal 进行了测试

windows #ubuntu #development windows #ubuntu #development

you might have bash but it is still a windows window manager.你可能有 bash 但它仍然是一个 Windows 窗口管理器。 Highlite some text in the bash terminal window.在 bash 终端窗口中突出显示一些文本。 Right click on the title bar, select "Edit", select "Copy", Now Right Click again on the Title bar, select "Edit" , Select "Paste", Done.右键单击标题栏,选择“编辑”,选择“复制”,现在再次右键单击标题栏,选择“编辑”,选择“粘贴”,完成。 You should be able to Highlite text, hit "Enter" then Control V but this seems to be broken您应该可以使用 Highlite 文本,然后按“Enter”然后按 Control V 但这似乎已损坏

For just copying (possibly long) texts to the Windows clipboard , I have found that just piping the output to clip.exe (including the .exe file extension) works fine for me.对于仅将(可能很长)文本复制到 Windows 剪贴板,我发现只需将输出管道clip.execlip.exe (包括.exe文件扩展名)对我来说效果很好。 So:所以:

$ echo "Hello World" | clip.exe

lets me paste Hello World using Ctrl - V anywhere else.让我在其他任何地方使用Ctrl - V粘贴Hello World

Now that I have posted this, I notice that related question Pipe from clipboard in linux subsytem for windows includes this and a command solution for pasting from the Windows clipboard as well.现在我已经发布了这个,我注意到相关问题Pipe from clipboard in linux subsytem for windows包括这个和一个用于从 Windows 剪贴板粘贴的命令解决方案

For autohotkey users, a full answer is:对于 autohotkey 用户,完整的答案是:

#IfWinActive ahk_class ConsoleWindowClass
^+v::SendInput %clipboard%

Which checks that you're in a console (windows or ubuntu) before pasting from the windows clipboard.在从 Windows 剪贴板粘贴之前,它会检查您是否在控制台(Windows 或 ubuntu)中。

That turned out to be pretty simple.结果证明这很简单。 I've got it occasionally.我偶尔会得到它。 To paste a text you simply need to right mouse button click anywhere in terminal window.要粘贴文本,您只需在终端窗口中的任意位置单击鼠标右键。

I can not get into Program Files/WindowsApps it has no owner!我无法进入没有所有者的 Program Files/WindowsApps! All I want to do is copy text from windows 11 GUI to Ubuntu - why is this impossible?我想要做的就是将文本从 Windows 11 GUI 复制到 Ubuntu - 为什么这不可能?

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

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