Copy and Paste in Screen
Put the mouse down, and copy and paste inside a terminal with your
keyboard using Screen.
Screen is a command-line tool that lets you set up multiple terminal windows
within it, detach them and reattach them later, all without any graphical
interface. This program has existed since before I started using Linux, but
first I clearly need to address the
fact that I'm even using Screen at all prior to writing a tech tip about it. I can
already hear you ask, "Why not tmux?"
Well, because every time someone tries to convince me to make the switch, it's
usually for one of the following reasons:
Screen isn't getting updates:
I've been happy with the current Screen feature set for more than a decade, so as
long as distributions continue to package it, I don't feel like I need any
tmux key bindings are so much simpler:
I climbed the Screen learning curve more than a decade ago, so to me, the Screen key
bindings are second nature.
But you can do vertical and horizontal splits in tmux:
you can do them in Screen too, and since I climbed that learning curve ages
navigating splits are part of my muscle memory just like inside vim.
So now that those arguments are out of the way, I thought those of you
still using Screen might find it useful to learn how to do copy and paste
within Screen itself. Although it's true that you typically can use your mouse
to highlight text and paste it, if you are a fan of staying on the home row
like I am, you realize how much faster and more efficient it is if you can
copy and paste from within Screen itself using the keyboard. In fact, I found
that once I learned this method, I ended up using it multiple times every day.
Enter Copy Mode
The first step is to enter copy mode from within Screen. Press Ctrl-a-[ to
enter copy mode. Once you're in this mode, you can use arrow keys or
vi-style keybindings to navigate up and down your terminal window. This is
handy if you are viewing a log or other data that has scrolled off the screen
and you want to see it. Typically people who are familiar with copy mode
just use it for scrolling and then press q to exit that mode, but once you
are in copy mode, you also can move the cursor to an area you want to copy.
To copy text once in copy mode, move your cursor to where you want to start
to copy and then press the space bar. This will start the text selection, and
you'll see the cursor change so that it highlights the text as you then
move the cursor to select everything you want to copy. Once you are done
selecting text, press the space bar again, and it will be copied to Screen's
copy buffer. Once text is copied to Screen's clipboard, it automatically
will exit copy mode.
Read More here.