I need to copy some text in Nano, so I searched using Google and found a few posts here on Stack Exchange and other sites in which the OP asks "How can I copy?" and people usually answer "You can use ctrl+K". The person asks how to copy and they are told how to cut.
Other answers mention alt+6 but in my testing it doesn't work.
Is there no option to copy text in Nano? Is there a workaround?
Position the cursor at the beginning of the character from which you want to copy. Press Alt+Shift+A to set mark. ( Alternatively, set mark with Ctrl+6 )
Use arrow keys to highlight the text to copy.
Use Alt+Shift+6 to copy (Alternatively, Alt + 6 )
Navigate to the place you want to paste. Release paste with Ctrl+U
Where is reference to these keybindings
All of these are defined under the documentation, which you can access with Ctrl+G at any point. Note that leading ^ stands for Ctrl and M for Alt in the documentation, since this is traditional way of Unix defining meta characters. Lines from documentation:
and
Workaround: cut, then uncut, and uncut again in the place where you want to copy the text.
I Ctrl+K
unicorns
I uncut Ctrl+U
I move the cursor to the end and Ctrl+U again
Yes copying text is a bit strange in nano, and somewhat confusing due to conflicting reports on the webs and lack of clarity (or common sense...) both in the way it was implemented (IMHO) and in the official docs...
Per the docs:
Since basically, you use CTRL+K to cut, CTRL+U to paste, and the cut line stays in the cutbuffer, you can do a quick cut and paste to replace, and then paste again to achieve a "copy."
But I don't like this "workaround"...
The last part of the docs, says how to copy: using ALT+6 (to copy) ad then pasting using CTRL+U to paste.
(Docs actually say "M" key, which means the Meta key, as mook765 said: "the
Meta
-key which does not exist"... and is usually just the ALT on modern keyboards.)You can also select multiple lines using ALT+6 and moving the section with your arrow keys.
Hope this helps.
Note that this solution only works in GUI versions of Ubuntu and not in a TTY interface.
I copy text in nano all the time just by doing CTRL+SHIFT+C on the selected text because that's the default key combo to copy any text in terminal. This applies to nano as well. This can also be found in
Edit > Copy
From
man nano
M
means theMeta
-key which does not exist on all keyboards but on some. On keyboards wihtout theMeta
-key other modifier-keys like Alt or Esc might work. On my machine i found that the combination Alt+6 works fine.you can also do the following;
nano -cm <text_to_edit>
Shift
+ LeftClick and drag mouse throuh the text you want to copy, pressCtrl+Shift+C
Ctrl+Shift+V
The options
-c
and-m
elaborated inman nano
:The easiest way that I find to copy text in nano is to select the text that you want to copy, with your mouse, and right click it. This will bring up a menu where it gives you an option of a few things one of witch is copy, select that option and you have copied the text. When you would like to paste the text do the same thing but select paste instead and it will paste the text.
mac pro m1: M=ESC