79

Left-down-clicking in xterms starts the selection of something to be copy-pasted.

Double-left clicking selects a word.

Triple-left clicking selects a line.

All this works under unity in 11.04. However, there is no way to copy-paste that selection to another place: The right-click menu shows paste disabled, and middle-clicking to copy-paste does not work.

So how can I copy a selection from an xterm into another place? I am happy with any method to perform this.

(I am using the default-installation no special configuration so far)

Edit: Same problem with xedit

Braiam
  • 67,791
  • 32
  • 179
  • 269
false
  • 1,852
  • 1
    It totally depends on your DE and terminal. – RobotHumans Jan 09 '13 at 00:47
  • @AbrahamVanHelpsing: I am using the default-installation, should have said this... – false Jan 09 '13 at 01:05
  • 1
    After selecting, you need to copy, then only can you paste. Just mentioning it because the way the question is written, it appears you want to go straight from select to paste. In other words, select with left-click, copy from the right-click menu, and paste from the right-click menu. –  Jan 09 '13 at 01:42
  • 1
    Are you using XTerm? (the software) or are you referring to Gnome Terminal as XTerm?. – Uri Herrera Jan 09 '13 at 02:01
  • @vasa1: But after the left-click selection, the right-click paste is still disabled! – false Jan 09 '13 at 02:48
  • @UriHerrera: I am using xterm, /usr/bin/xterm – false Jan 09 '13 at 02:49
  • After you click, double-click or drag to select text, if you then immediately single right-click what do you see? Don't you get a context menu with "copy" as one of the options? –  Jan 09 '13 at 02:58
  • @vasa1: To be clear: I perform this within the xterm. So I click and drag (or double click a word). Then I right-click which changes the selection (the highlighted text) and no menu appears. Even more so: I cannot paste the selection back into the xterm (in this case there is a bigger change that no other application is involved). – false Jan 09 '13 at 03:11
  • @vasa1: I have just reread your question: Within xterm I do not get the menu. And outside of xterm I get the menue, but with copy and paste disabled. – false Jan 09 '13 at 03:33
  • You are right. I just assumed a regular terminal such as gnome-terminal or lxterminal. I guess xterm is very basic and won't have the features you desire. –  Jan 09 '13 at 03:38
  • @vasa1: So your answer is: xterm should no longer be used, use instead xyz. Could you please write this answer, then I can mark it? – false Jan 09 '13 at 03:45
  • I would rather you compare gnome-terminal and xterm for yourself with your needs in mind. You can then answer your own question with your findings and accept your own answer. I do not have any experience with xterm except now when I tried to see whether I could reproduce your issue. I use the regular terminal (gnome-terminal or lxterminal (with LXDE)) for my needs. –  Jan 09 '13 at 05:54

14 Answers14

57

Use middle click or Shift + Insert

See X Window selection.

Pablo Bianchi
  • 15,657
strings
  • 1,374
  • 3
    Middle click did not work, nor did Shift-Insert (which I have never heard of, but I tried). E.g., I try to copy-paste something into the text-box I am just writing... – false Jan 09 '13 at 00:52
  • 4
    X has two clipboards if you select something in xterm, it will goto the cut buffers, in which case you can paste with middle click or shift+insert. which is not the same concept as copy an paste. – strings Jan 09 '13 at 00:56
  • I added a link to help explain the X 11 selection process. – strings Jan 09 '13 at 00:58
  • Thank you. But how do I now get under unity a text from an xterm into another app. Previously, (I used karmic), I simply used middle click as you suggest. But now, under unity, or 11.04; neither middle-click nor shift-insert works. – false Jan 09 '13 at 01:03
  • 1
    Isn't it Control+Shift+v – Uri Herrera Jan 09 '13 at 02:00
  • @UriHerrera: Does not work. That is: It neither "enables" the right-click menu paste option, nor does it paste. – false Jan 09 '13 at 02:51
  • selecting text for the cut buffer will not enable paste. they are two different things. – strings Jan 09 '13 at 03:03
  • @strings: I agree ; but I tried both since I was not sure what UriHerrera meant by "it". – false Jan 09 '13 at 03:13
  • @false select text in xterm. then middle click in another window should paste. if that does work try other windows, baring that as far as I can see it might be a bug or something related to you system. – strings Jan 09 '13 at 03:19
  • @strings: I did try this already ; it even does not work when I try to middle click in the same xterm! Even that does not work. (One typically does this when a command-line program suggests another command in the text-output) – false Jan 09 '13 at 03:22
  • 1
    if shift+insert does work either, then we can rule out its your mouse. are you using some clipboard manager. xsel or something like that? – strings Jan 09 '13 at 03:27
  • 1
    This answer doesn't address copying specifically, it doesn't quote the relevant part of the link, it ignores the part of the question that states "middle-clicking to copy-paste does not work," and it doesn't answer how to use the X11 clipboard (which means it is useless for an expansive use-case). – SO_fix_the_vote_sorting_bug May 30 '18 at 03:33
40

Xterm uses cut buffers, not the standard X11 clipboard selection used for standard copy-paste that gnome-terminal and most other Linux programs now use.

But if you start xterm like this:

xterm -ls -xrm 'XTerm*selectToClipboard: true'&

then selections are available via the standard clipboard.

Read more at Copying and Pasting in Xterm | StarNet Knowledge Database - PC X, X Windows, X 11 & More - StarNet

The xcb program also provides command-line access to the cut buffers.

E.g. in Trusty Tahr 12.04, running lxde window manager, I can triple click on a line of text in xterm, which highlights it and puts it in cut buffer 0. I can then run xcb -p 0 which prints the line out on stdout.

For some reason it didn't work for me to click both buttons (simulating middle click) in an xterm, but shift-insert did work in an xterm.

nealmcb
  • 3,647
  • 7
    +1 - solved for me. As this question comes up in searches for questions such as "How to copy in xTerm," it's worth adding that if you have a .Xresources (or similar) file set up, you can add the xterm*selectToClipboard: true line there to make the change persistent :) – Ashley Davies Oct 25 '16 at 21:24
  • Stefan's answer explains how to ensure the setting in Ashley's reply gets read (worked for me on Fedora 29--I didn't try it without Stefan's extra xrdb step, but he also mentions you have to restart xterm though that may be obvious to most people) – Poikilos Feb 11 '19 at 23:00
  • Note that if you use -class ${CLASS} to launch xterm the corresponding flag becomes -xrm ${CLASS}.*.selectToClipboard:true so if you have separate xterm window classes, settings are tracked separately. – stevesliva May 30 '19 at 20:42
  • I don't understand the need for "-ls" option though. Actually it seems to work just fine without it. – desgua Sep 08 '20 at 15:49
  • The exact terms are not quite right: xterm doesn't use the cut buffer. It uses the primary (selection, middle click) buffer, as opposed to the clipboard (ctrl-c) buffer. There is also a cut buffer, but that is still something else – johannes_lalala Feb 21 '22 at 18:30
18

To copy between xterm and other programs/documents/...

Add to the file ~/.Xresources (or create):

XTerm*selectToClipboard: true

Then run the command:

xrdb -merge ~/.Xresources

Restart xterm.

Yaron
  • 13,173
Stefan
  • 191
11

A similar issue is discussed here. As "strings" pointed out:

X has two clipboards if you select something in xterm, it will goto the cut buffers, in which case you can paste with middle click or shift+insert. which is not the same concept as copy an paste.

Copy/paste within xterm worked for me but not to an application outside, example gedit. As per the link above, I installed parcellite and that fixed the problem,

sudo apt-get install parcellite

Update: If "paste" does not work with "shift-insert", then use the middle mouse button or if you do not have one click both the left and right buttons simultaneously to paste.

Eric Carvalho
  • 54,385
  • 1
    For a little more clarity, after installing parcellite, run it. It sits in your system tray. Right-click > Preferences, then check "Use Primary" and "Synchronize clipboards". Now select something in Xterm, and you can then Ctrl-V elsewhere. – Ian Gibbs Dec 12 '15 at 06:41
  • thanks it worked , but once you install paracellite restart your terminal – user889030 Jul 31 '19 at 07:26
7

When you copy from xterm, just use Shift+Middle click to paste something into gedit or some editor in xterm like mcedit

zx485
  • 2,426
5

To copy text in Xterm first select the text and then press shift+PrtScr. To paste text in Xterm use shift+Insert .

Ankush K
  • 225
4

This does not quite answer your question, but it helped me, so am putting it here as it may help someone else:

  1. Copy what you want from xterm by selecting your text
  2. Open a second copy of xterm and your favorite text editor (I use vim)
  3. Use Shift+Insert (or middle-click) to paste into your text editor
  4. Save the file.
  5. If necessary open the file with a graphical text editor (such as gedit)
  6. Copy your text and paste it into the application that you want.
kojow7
  • 149
3

If you want to retain support for PRIMARY and still be able to use the CLIPBOARD (this is cool since basically you get two clipboards instead of one), you can ignore selectToClipboard and set the translations resource instead:

*VT100*translations:    #override \n\
    Ctrl <KeyPress> Insert: copy-selection(CLIPBOARD) \n\
    Shift <KeyPress> Insert: insert-selection(CLIPBOARD)

After that, if you select a text with your mouse it will get copied to PRIMARY, and a middle-mouse click will paste the text back from PRIMARY, just like the default XTerm behaves.

At the same time, Ctrl+Insert will copy the text to CLIPBOARD and Shift+Insert will paste it, similarly to modern GUI applications.

If you wish, you can add more key bindings in a similar way, and you can also have more than two clipboards by using X Cut Buffers (they can be referenced as CUT_BUFFER0, CUT_BUFFER1, etc.). More on X Cut Buffers here.

See also this question.

Bass
  • 151
3

Xterm uses the primary X11 selection, which is different to the clipboard. The program xsel can be used to copy the primary selection into the clipboard:

xsel -op | xsel -ib

In order to do so I have defined Meta-c in Fluxbox for this.

Mod4 c :Exec xsel -op | xsel -ib

This is handy for Windows programs, which support only one clipboard (for example VirtualBox).

ceving
  • 311
2

When you select text, it's put automatically in the cut buffer (like a clipboard). When you use Copy, from a menu, or with a keyboard shortcut, it goes into the main clipboard.

To paste from the cut buffer into your xterm, middle-click. To paste from the clipboard into your xterm, shift middle-click.

Greg Bell
  • 516
  • 4
  • 8
1

What worked for me was extracted from https://www.davidsimmons.com/soft/xtermhacks/#copynpastenopatch

Summary: Add to ~/.Xresources

XTerm*VT100.translations: #override <Btn1Up>: select-end(PRIMARY, CLIPBOARD, CUT_BUFFER0)

and the run xrdb -merge ~/.Xresources.

Rodrigo
  • 21
1

Emacs command (put it in your ~/.emacs init file) to ignore the selection and use the primary:

;; Get highlighted text from any window,
;; e.g., drag the mouse in xterm
;; then press Super-V in Emacs.

(global-set-key [(super v)] (defun yank-x11-primary () "Insert highlighted x windows text." (interactive) (insert (gui-get-primary-selection))))

Devon
  • 111
1

See here for an explanation of paste problems with xterms and modern apps/window managers: http://www.davidsimmons.com/soft/xtermhacks/#copynpaste

Brent
  • 19
  • 1
0

I have otherwise useful Glipper clipboard manager running on 12.04.
If I select xterm characters, they appear in a new Glipper's entry.
If I select that entry (button) among that succession, the next paste will come from it and paste those characters into any application.

Papou
  • 129