Since I first learned that Windowmaker installs two command-line tools, wxcopy and wxpaste, to play around with X selections, I have wanted to be able to make and use X selections from my Bash shell. wxcopy and wxpaste never did what I expected them to do, so I gave up until recently I learned about all the different X selections.
By default, wxcopy and wxpaste operate on the CUT_BUFFER[n] selections. These are deprecated. That’s why I could never make it work, because modern applications use only CLIPBOARD and SELECTION. So, wxcopy is pretty useless (unless its used to copy something to paste with wxpaste). With this knowledge wxcopy does seem useful thanks to its -selection [selection-name] flag, but this doesn’t seem to work; I only get the contents of CUT_BUFFER. This is not how the feature is advertised:
- -selection [selection-name]
- The data will be copied from the named selection. If cutting from the selection fails, the cutbuffer will be used. The default value for the selection name is PRIMARY.
Among its features are: --append, --follow, --clear, --delete (very weird, but logical if you understand X IPC), --primary, --secondary, --clipboard, --keep, and --exchange. Read the man page for more. It’s an excellent read.
One of the places where I’m going to use this tool is when copy-pasting to and from VIM. I really like how this compares to using :insert or :r!cat</dev/tty and then using the pointer to paste (or (Shift+)Insert with my custom XTerm config). Now, to paste something in VIM, I can simply type:
I use the following to copy any amount of text from VIM. This works much better than fooling around with the mouse:
:'>,'> !tee >(xsel -i)
'>,'> range is entered automatically if you press : while in visual (selection) mode. You could enter any range there, or even % to select the whole file. To copy to the CLIPBOARD instead of the PRIMARY, use
xsel -i -b in the above example.
If someone know of a way to make VIM pipe something to a program without replacing the given range with that program’s output, I could simplify thisâ€¦