Making Xterm Play (Mostly) Nice With Copy-And-Paste (and Not Look Ugly Too)

Some guys work on cars;  I work on getting the last little bit of performance and customization out of my computer.

That’s why I’m using Xterm (if I’m not using screen) for terminal applications.  Especially since I’m constantly starting up and closing terminal windows, the small difference in startup times between it and my GNOME terminal gets…annoying.

However, there’s some issues setting up Xterm.  It’s finicky.  It is, by default, ugly as sin. I like a nice black terminal, the lovely Inconsolata monospace font and generally the clean look that you can get with it.  That’s the first part of the .Xresources file – setting up those colors so it behaves nicely.

Xterm is also, shall we say, not fond of the way the clipboard is handled in *nix.  (There’s three clipboards, see… no, really.)  Anyway, I hate the “select it with the mouse and that puts it on the clipboard” method that *nix seems to prefer.  I’m too sloppy with the mouse, especially when using a touchpad.  So with this .Xresources, I can select by holding SHIFT and the mouse button, and then it copies it to all the clipboards. The key elements are here (I highly recommend copying from the gist later):

XTerm*VT100.translations: #override
<Btn1Up>: select-end(PRIMARY, CLIPBOARD, CUT_BUFFER0) n
Shift<Btn1Down>: select-start() n
Shift<Btn1Motion>: select-extend() n
Shift<Btn1Up>: select-end(PRIMARY, CLIPBOARD)

Yes, there’s a duplication in there. Find it for extra points – it works right now, and I’m not messing with it any more.

Anyway, this is something that took a while to research and set up, so hopefully this will be of some use to other power users out there. (Not to mention typos, control characters, or brackets and the like being entirely missing…)

This is my .Xresources file; you edit (or create) it in your home directory.  Once you’ve edited .Xresources, run this command from your terminal:

xrdb -merge .Xresources

Despite what lots of web pages say, sometimes it shows up right away. Sometimes it required me to restart X (effectively relogging). If it doesn’t behave as expected, relog and see if it does what it’s supposed to then. You can get the .Xresources file from gist on GitHub or the embed below. I cite where I got the bits of this solution at the top of the .Xresources file if you’d like to do some additional reading.