If you're dealing with files discovered via ls
, I usually find it easiest to tab-complete or glob them: if I want to act on report.tex
, for example, it's faster to do vim re<TAB>
than to copy-paste.
But copy-paste does have its uses, certainly. I do most of my work in tmux
with vi bindings. If you have emacs bindings (the default) the approach is similar (below, C-
means "press Control and then the key after the dash togehter", A-
is similar but for Alt, and prefix
is your prefix, probably C-b
):
- In either, press
<prefix>[
to enter copy mode
- Navigate to either end of the text you desire copied using arrow keys (always) or
hjkl
(vi mode only, probably?)
- If in emacs mode, press
C-<Spaaaaaace>
to begin the selection. If in vi mode, press <Spaaaaaace>
.
- If in emacs mode, press
A-w
to copy the selected text. In vi mode, press <Enter>
.
- Paste the selection with
<prefix>]
or use the command tmux show-buffer
to output to stdout the copied text, useful for piping into commands and automation.
Tmux remembers what you copy when you copy other things. See the list of what's been copied with <prefix>#
. <prefix>]
pastes the most recent, but tmux show-buffer
can take a -n <number>
argument to output an older copy.
I don't know how to copy in screen
off the top of my head, but it's a roughly similar process; I'm sure there's a wealth of blog posts about it on google.
Edit: I definitely recommend using a terminal multiplexer in general; you'll have another terminal at your disposal in three keystrokes regardless of terminal emulator or window manager. Muscle memory is good!
xsel
, I believe it can do this. Alsoxclipboard