Copy (only copy, not cutting) in Nano?

  1. 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 )

  2. Use arrow keys to highlight the text to copy. highlight with nano image

  3. Use Alt+Shift+6 to copy (Alternatively, Alt + 6 )

  4. Navigate to the place you want to paste. Release paste with Ctrl+U

    paste image

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:

^^ (M-A) Mark text starting from the cursor position

and

M-^ (M-6) Copy the current line and store it in the cutbuffer


Workaround: cut, then uncut, and uncut again in the place where you want to copy the text.

unicorns
rainbows

line4

I Ctrl+K unicorns

rainbows

line4

I uncut Ctrl+U

unicorns
rainbows

line4

I move the cursor to the end and Ctrl+U again

unicorns
rainbows

line4
unicorns

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:

4.3 The Cutbuffer

Text can be cut from a file, a whole line at a time, by using the ’Cut Text’ command (default key binding: ^K). The cut line is stored in the cutbuffer. Consecutive strokes of ^K will add each cut line to this buffer, but a ^K after any other keystroke will overwrite the entire cutbuffer.

The contents of the cutbuffer can be pasted back into the file with the ’Uncut Text’ command (default key binding: ^U).

A line of text can be copied into the cutbuffer (without cutting it) with the ’Copy Text’ command (default key binding: M-6).

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.

Tags:

Nano