15
10
How do I copy a few lines from one file to another file using the nano editor?
15
10
How do I copy a few lines from one file to another file using the nano editor?
17
Assuming you are in pure console mode and can't use the mouse to copy/paste:
NOTE: To switch between buffers use either ESC-< and ESC-> or ESC-, and ESC-. (the later is helpful if < and > use the same key on your keyboard layout)
An alternative to 2-4 above is to go to the line(s) you want to copy and CTRL-K to delete them, pressing CTRL-K repeatedly to multiple lines to the buffer. When you've cut all the lines you want to copy, CTRL-Y to re-paste them back into the current buffer. Then continue with step 5.
ALT or any other keys with Meta-key behaviour could also be used instead of ESC in these commands.
10
Copy text from one file to another with nano text editor
Note: To help you understand better, we will use a
source file: /var/named/athens.local
destination file: /var/named/patra.local
nano -F destination_file
So we have:
nano -F /var/named/patra.local
Press Ctrl+r.
From inside nano editor, open the source file
/var/named/athens.local
Press ctrl+^ (this will enable the "mark set" mode)
Select your text.
When you have marked all the text you want, copy the text to
clipboard by pressing Alt+^
Note: Now your text is in clipboard.
Note: In help file you will see the Alt+^ described as M-^.
Press ctrl+x, to close the source file (/var/named/athens.local
).
Now we will see the destination file (/var/named/patra.local
).
Move the cursor to the place you want to paste the copied text (which is
in buffer, don't forget that).
Press ctrl+u, to paste the text.
You are done.
I like this answer better than the accepted answer because you explain step by step what is actually happening. Thank you. – vrijdenker – 2016-04-08T08:11:48.247
This is extremely clear thank you. To anyone else wondering - the ^ symbol really does mean Shift + 6. So to set the mark it's Control + Shift + 6 on a Windows / Linux keyboard. And to save to clipboard it's Alt + Shift + 6. – anon58192932 – 2016-04-21T14:01:13.247
What key is ^ for steps 2 and 4? And what keys are 'ESC-<' and 'ESC->'? Is it Escape and then hyphen and then shift comma / period all together? – anon58192932 – 2016-04-21T13:55:59.107
The instructions above are generally correct, but on step five skip the ESC-F in order to open the second file into it's own area. Following the instructions above (and typing ESC-F) will instead insert the second file into the first file (which is probably not what you want. – Eptin – 2017-06-01T20:13:38.980
Additionally, on some systems (such as on Raspbian), you may be able to use the 'Alt' key instead of the 'Escape' key. (In some discussion about Nano, the Escape key and Alt key are referred to as the 'Meta' key). – Eptin – 2017-06-01T20:21:12.667