82

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
  • 69,112
false
  • 1,762

15 Answers15

59

Use middle click or Shift + Insert

See X Window selection.

Pablo Bianchi
  • 17,371
strings
  • 1,394
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,715
19

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,453
Stefan
  • 301
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
  • 55,453
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,865
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
  • 3
  • 7
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

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
  • 535
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
  • 351
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

Personally, I wanted xterm's behavior to match gnome-terminal which works much more intuitively by default:

  • Copy with Ctrl+Shift+C
  • Paste with Ctrl+Shift+V
  • Copy/Paste into other applications should "just work"

To get this behavior, I used the following ~/.Xresources configuration:

*VT100*translations:      #override \n\
    Ctrl Shift <Key>C:  copy-selection(SELECT) \n\
    Ctrl Shift <Key>V:  insert-selection(SELECT)

xterm*selectToClipboard: true

After editing this file, I had to run sudo xrdb ~/.Xresources then restart xterm. (Note that this xrdb command replaces any currently loaded settings - you can use xrdb -edit /tmp/xresources to dump the currently loaded settings into /tmp/xresources).

Brandon
  • 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
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