Access X11’s clipboard from tty1-6

clipboardttyvimx11

Sometimes, when I'm running on battery and don't need a window manager, I'll log into tty1, fire up fbterm and Vim and work. Later, if I need the window manager, I'll use the log in GUI but switch between them as required.

The only issue I have with this, is when copying and pasting. If I'm running Vim in a terminal emulator, I can copy from a browser and paste into vim using "*p. When I'm running it in tty0, I can't (for obvious reasons, I guess).

Is there a way I could share between them. For instance, automatically dumping the clipboard contents―when it changes―to a file and then using a macro to insert the contents into the current Vim buffer?

Best Answer

I don't have an X11 machine around so I can't verify this myself, but you might want to look at a program like xclip:

xclip is a command line interface to the X11 clipboard.

That won't exactly let you paste into your current tty, but it should at least print the contents of the clipboard to stdout. Then you can capture that into a file, or pipe it to a command, etc:

DISPLAY=:0 xclip -o | sort

Your DISPLAY environment variable needs to point to your X11 display, which is unlikely to be set by default, so you'll want to set that as above, or like the following if you want it to be around for the duration of your shell session:

export DISPLAY=:0
xclip -o

(This may need tweaking if your display isn't :0 or if you need to deal with Xauthority issues, etc.)

I found this article about it as well which may be helpful: http://www.susegeek.com/utility/xclip-copy-contents-from-command-line-to-x-clipboard-in-opensuse/