Xterm is a terminal emulator for Linux that I like a lot. For some reason it’s not the default emulator in any distro that I know of. This post is about how to make Xterm select-and-copy-to-clipboard with mouse.
One of the features I like in Xterm is the way copy and paste work there. Namely, it’s not emulating modern word processors in this, where you Ctrl+C (or, more often, Ctrl+Shift+C) to copy and Ctrl+V (Ctrl+Shift+V) to paste. Instead, the mouse works there in peculiar ways that may seem cumbersome at first, but make sense later, after some infotechnological enlightenment.
The move to copy
Xterm allows copying with mouse this way:
- Select a letter (Left-click+Drag)
- Release the mouse button and move the mouse where you want to end the selection
- When the mouse pointer is where you want to end the selection, Right-click
This selects everything from the first selected letter (which was really only to mark the beginning of the selection) to the right-click. In truth, this move both selects and copies, but it’s not obvious that it copies.
Multiple buffers
Terminal emulators distinguish three buffers, two of which are important – at least for my purposes. The two important buffers are Primary and Clipboard.
The described move to select text in Xterm also copies it at the same time to the primary buffer. This means it’s possible to paste it (with Ins or Shift+Ins or a keyboard shortcut specific for the program open in the emulator) in Xterm only, not paste it elsewhere in the desktop. To be able to copy from Xterm and paste elsewhere, a tweak is necessary.
The tweak to copy to the clipboard in Xterm
Note: The tweak will copy to the clipboard buffer, not only to primary. This will make the distinction of primary and clipboard buffers disappear. If you need the distinction, don’t use this tweak.
In your home folder, a text file named .Xresources or .Xdefaults probably already exists. If not, create it. Create just one of these, not both.
In the file, paste this line:
XTerm*VT100.translations: #override : select-end(PRIMARY, CLIPBOARD, CUT_BUFFER0)
Save the file. To make the function take effect immediately, issue this command in the terminal:
xrdb -merge .Xresources
If you created the file by the name .Xdefaults, use that name instead of .Xresources. All this done, the described move to select text with mouse in Xterm should do select-and-copy-to-clipboard so that it can be pasted to any other program on the desktop.