Use the following tmux.conf
with copy-pipe
in the new versions of tmux (1.8+):
set -g mouse on
# To copy:
bind-key -n -t emacs-copy M-w copy-pipe "xclip -i -sel p -f | xclip -i -sel c "
# To paste:
bind-key -n C-y run "xclip -o | tmux load-buffer - ; tmux paste-buffer"
prefix+[
into copy-mode
- select content with mouse(hold)
M-w
to copy that part into system clipboard
C-y
the paste it inside tmux, C-v
to paste it inside other regular application like web browser.
With xclip
:
while IFS= read -r line; do
printf %s "$line" |
xclip -l 1 -quiet -selection clipboard -in
done < file.txt
Replace %s
with %s\n
if you need the newline included.
With -l 1
xclip holds the CLIPBOARD
selection for one request (by other applications doing Ctrl-V for instance), and then exits. You need -quiet
for xclip
to do that in foreground.
That won't work if you have an application like xclipboard
running. Those applications try to always be the owner of the CLIPBOARD
selection, so will steal it continuously from xclip
.
If you have such an application running, you can either suspend or kill it, or you could use the PRIMARY
selection instead (-selection primary
, or omit -selection
as primary
is the default) and paste using the middle mouse button. Many terminal emulators can paste the PRIMARY
selection upon Shift-Insert, some other upon Ctrl-Shift-Insert.
If you want to know who is stealing the CLIPBOARD selection from xclip
, this may work:
xwininfo -id "$(xclip -selection clipboard -o -t CLIENT_WINDOW | od -vAn -tu8)" -wm
provided that application offers the CLIENT_WINDOW target (run xclip -selection clipboard -o -t TARGETS
to see if it does).
See also expect
(and dejagnu
for a testing framework based on expect
) and GNU screen
to automate inserting text into terminal applications.
Best Answer
X11 has several available clipboards. By default,
xclip
places data in the primary selection buffer. To paste it, you use middle-click.If you want to use Ctrl+v, use
xclip -selection clipboard
. Seeman xclip
for more information.There is good information about the different clipboards on freedesktop.org.