93

I have an Ubuntu server hosted by Vultr which I am interacting with remotely using their provided terminal. I would like to know how to paste from my clipboard into nano, which I am using to write the code for my server. I have tried Ctrl+U but this does not work for me.

Other keyboard shortcut commands work, such as write out Ctrl+O and quit Ctrl+X, so I am sure that the Vultr terminal can recognise these keyboard commands.

I'm sure there is a way to paste into nano from the clipboard but I'm not sure what the shortcut is.

Question: What is the keyboard shortcut to paste from clipboard into nano? If there is no way to do this, what native Linux editor is capable?

1
  • Did you try right clicking on the terminal that you are running your SSH session in? Some terminals use right click for paste.
    – jrh
    Oct 25, 2017 at 11:58

9 Answers 9

111

You could try the following two commands to paste from the clipboard. Both of them should work.

  1. Ctrl+Shift+v

  2. Shift+Insert

The Ctrl+U command only allows pasting text that was copied or cut from within nano itself, hence the reason the command is not working.


Edit:

Unfortunately, for the specific case when using Vultr console, there seems to be no easy way of using copy and paste. Vultr simply does not support it. An alternative would be to use SSH together with another terminal to connect to the server. If you are on Windows, using putty would work.

5
  • 3
    The paragraph after the numbered list is correct. The nano command does not try to access the clipboard of a GUI. (You may have multiple clipboards. Using Ctrl-K from nano, to cut, will use nano's internal clipboard.)
    – TOOGAM
    Oct 25, 2017 at 5:43
  • 1
    I'm using Terminus and it worked for me - yay
    – Nick.Mc
    Nov 8, 2017 at 0:42
  • why this is not mentioned in the help section of nano I am wondering. how did you come to know?
    – xpioneer
    Feb 11, 2021 at 7:38
  • On windows it is right shift + insert.
    – osemec
    Apr 21, 2021 at 7:10
  • @xpioneer from nano help: ^U (F10) Uncut from the cutbuffer into the current line. Oh, 'uncut', great. Sep 15, 2021 at 9:08
41

SSH Putty windows Shift+right mouse click worked for me with default putty settings.

2
  • 3
    It works for Windows 10 subsystem ubuntu.
    – user2165
    May 17, 2020 at 18:29
  • Works on macos as well Jul 2, 2022 at 19:44
16

I successfully used right mouse button to paste from Windows 10 to nano on "Bash on Ubuntu on Windows".

4
  • 1
    Worked for me: Windows 10 10.0.17763 to Nano in a Linux container
    – JohnC
    Sep 20, 2019 at 12:53
  • Same here. Win10 2004 19041.450. Aug 31, 2020 at 23:32
  • 1
    only thing that worked for me: accepted answer didn't work
    – neuronet
    Sep 27, 2021 at 2:07
  • 1
    Nice! Works in Windows Terminal as well.
    – Neeraj
    Jan 14, 2022 at 14:07
9

nano itself has no system clipboard integration; it is dependent on the terminal's clipboard handling for interacting with it.

From the Vultr documentation:

Notes about console: The console software does not support cut & paste.

If you want clipboard handling as given in the question then you will have to use a SSH program and terminal that supports it.

4
  • As a nano user myself, I can tell you that nano does indeed have a clipboard, accessed via CTRL+K to cut out a line and CTRL+U to paste it again.
    – MechMK1
    Oct 25, 2017 at 9:00
  • 4
    It has a cutspace, yes. But no system clipboard integration. Oct 25, 2017 at 9:00
  • Your answer mentions nano "having no clipboard capability", which is not the same as "not integrating the clipboard of a window manager".
    – MechMK1
    Oct 25, 2017 at 9:03
  • 1
    @MechMK1 a "clipboard" is a system-wide concept that provides inter-application operation, nano does not support this.
    – Attie
    Oct 25, 2017 at 9:18
1

If there is no way to do this, what native Linux editor is capable?

I'm not sure if Nano actually can do this more or less natively without explicit support from the terminal, but you may want to use X11-enabled Vim over an X11-forwarded session (ssh -X). Then "+y command will yank ("copy") to the X11 clipboard, and "+p will put ("paste") from there — without the need for terminal to support this.

Note that X11-enabled Vim doesn't mean GUI version (gVim). Console Vim can remain in the terminal, but is still able to access X11 clipboard thanks to being linked with X11 libraries. It just has to know your (forwarded) DISPLAY.

1

I recently ran into a similar problem trying to copy from windows and paste a really long "private key" via a terminal using Nano and could not get copy and paste to work. Instead of manually typing it by hand, I was able to use a text expander (I used AutoHotKey) to enter it that way.

1

The following applies when accessing Nano via a PuTTY terminal window.

If you have a ~/.nanorc file or /etc/nanorc containing set mouse, then:

  • Pasting clipboard contents into Nano requires shift+right click or shift+insert.
  • You can mark blocks of text in Nano by clicking the mouse.
  • You cannot select text with the mouse to copy it to the Clipboard (a PuTTY function), but you can mark text in Nano and copy it to the buffer with Ctrl + K, so you can paste with Ctrl + U.

If you change the ~/.nanorc setting to unset mouse, then:

  • Pasting clipboard contents into Nano requires a regular right click (or shift+insert).
  • You can mark blocks of text in Nano only with the keyboard using Alt + A followed by the arrow keys. These can be copied to the buffer with Ctrl + K.
  • You can select text with the mouse to copy it to the Clipboard (a PuTTY function).

When pasting text from the Clipboard (via PuTTY) into Nano, the pasted text may auto-indent improperly. You may have to specify unset autoindent in ~/.nanorc to resolve this.

1
  • shift+right click worked for me in Linux Mint's implementation of GNOME Terminal 3/5/2023
    – DeltaFlyer
    Mar 6, 2023 at 2:36
0

I found a great way to do so if the button combinations doesn't work for you!

If you are able to paste into the command line itself, then you can do this:

echo "INSERTED_TEXT" >> "FILE_NAME"

It will merely APPEND your text to the file. After this operation you can conveniently CUT and PASTE what you need and where you need it!

CAUTION THOUGH!!! In case if you type ">" operator instead of ">>" you will OVERWRITE the whole file

0

I was using nano in an Azure Serial Console and noticed that size seemed to matter. I also had to use right click then paste. The keyboard shortcuts didn't work. But I found pasting 10 lines at a time worked okay but pasting an entire large document didn't work for me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .