How can one copy text from nano in Ubuntu WSL2 and paste it into a Windows application?

10,584

Solution 1

The usual way is selecting the text with the mouse and right click for copy.

You can also use clip.exe to copy all the content of a linux file to Windows Clipboard.

cat ~/.ssh/id_rsa.pub | clip.exe

Solution 2

Select the text with the left mouse button and press once on the right mouse button to copy on the Windows clipboard.
Now you can paste the copied text in WSL with another right button click, or paste in Windows with CTRL-V.
So when you want to copy/paste in WSL, you press the buttons left (select the text with the mouse), right, right.

Edit: Part beneath was a comment:
In Nano first change the layout to soft wrapping (soft: don't insert real new lines) . Nano help explains: Meta-key sequences are notated with 'M-' and can be entered using either the Alt, Cmd, or Esc key, depending on your keyboard setup. and M-$ Soft wrapping of overlong lines enable/disable. With my keyboard layout ($ above the 4) this results in ALT-SHIFT-4. Now the long lines are wrapped and visible in the screen.

Share:
10,584

Related videos on Youtube

davemackey
Author by

davemackey

Love to code: Python, JS, C#, PHP, SQL, VB.NET, HTML, CSS. In ancient days I coded in QuickBasic, ASP, and VBScript. I'm a friendly introvert with solid communication skills. I work hard and have refined problem solving skills. When I was younger I worked in a variety of industries (commercial fisherman, stone mason, lawn care, factory, custodial, youth leader). I settled on IT and have experience working in a startup, higher education, and with non-profits.

Updated on September 18, 2022

Comments

  • davemackey
    davemackey over 1 year

    Microsoft has made this nifty tool called Windows Subsystem for Linux. WSL2 creates a lightweight VM running Linux (in this case Ubuntu) to facilitate using Linux on Windows.

    Within WSL2 (Ubuntu) I've run: sudo nano ~/.ssh/id_rsa.pub. I attempt to use the normal nano method for copying. I can't then paste it on the Windows side.

    Ends up WSL2 has its own key combination for copying/pasting between Linux/Windows and that you need to enable it within WSL.

    I enable the function within WSL and use Ctrl+Shift+C to copy the text as instructed. Ctrl+Shift+V into a windows app does nothing.

    I use the regular nano method to copy (Alt+Shift+A to mark, arrow keys to select, Alt+Shift+6 to copy) and then paste using Ctrl+Shift+V into a Windows app, still no luck.

    What am I missing?

  • davemackey
    davemackey over 4 years
    Haha, yes, I know that. Thanks.
  • davemackey
    davemackey over 4 years
    Thanks, I did end up copying the file over to Windows, but would still like to know how to use copy/paste with WSL2 to extract text from nano.
  • davemackey
    davemackey over 4 years
    What if the text is one long line and runs off the visible screen? For example, an SSH key opened in nano? In this case the mouse cursor will not cause nano to move right so the entire string can be selected.
  • Walter A
    Walter A over 4 years
    In Nano first change the layout to soft wrapping (soft: don't insert real new lines) . Nano help explains: Meta-key sequences are notated with 'M-' and can be entered using either the Alt, Cmd, or Esc key, depending on your keyboard setup. and M-$ Soft wrapping of overlong lines enable/disable. With my keyboard layout ($ above the 4) this results in ALT-SHIFT-4. Now the long lines are wrapped and visible in the screen.
  • Fons MA
    Fons MA over 3 years
    The soft-wrapping makes this answer work; perhaps put it on your main answer? How ridiculous is it though that you have to point and click to copy on a CLI program...