Copying and Pasting in Xterm


When highlighting a selection in xterm you may notice that the selection does not get sent to the clipboard (and therefore you cannot paste).
This is due to the fact that FastX only uses the CLIPBOARD buffer for copying and pasting text. xterm by default only supports the PRIMARY buffer.

Solution

Launch an xterm with the selectToClipboard option set i.e. : xterm -ls -xrm ‘XTerm*selectToClipboard: true’

If you choose the Xterm option in the suggestions, this command is automatically run

Alternatively, add the following line to your $HOME/.Xdefaults file:

  • XTerm*selectToClipboard: true

Background

X applications have multiple copy buffers when selecting text, two of which are PRIMARY and CLIPBOARD. FastX reads the contents of the CLIPBOARD buffer only.

  • PRIMARY
    • The “PRIMARY” selection buffer receives data when the user highlights text with the mouse. The text in this buffer is pasted when the user presses the middle mouse button in an application’s text entry field. This cut-and-paste buffer is a legacy function which new users are generally not told about, in the interests of avoiding mass confusion. Most modern applications support this buffer. This is the only buffer used by xterm.
  • CLIPBOARD
    • The “CLIPBOARD” selection buffer is used for the cut-and-paste functions that most users are familiar with: Selecting the “cut”, “copy” or “paste” menu items from the application’s “Edit” menu, or using the corresponding CTRL-X, CTRL-C, or CTRL-V shortcut keys. This selection buffer is the standard means of performing cut-and-paste operations in most modern applications. However, this selection buffer is unfortunately not used at all by xterm in the default configuration.

Because of the use of multiple buffers, text highlighted in xterm cannot be pasted into a modern application with CTRL-V (or Edit->Paste). The PRIMARY buffer is often overwritten by inadvertent highlighting before the user is ready to paste.

For example, if a user highlights a URL in an xterm, switches to Firefox, and presses ALT-D to navigate to the URL bar, then Firefox will automatically highlight the old contents of the URL bar, thus overwriting the highly volatile PRIMARY buffer before the user can paste the new URL!

More Information