Blog posts about free software,
usage, configuration and my involvement in free software
Posted by Sebastian Humenda at 02.04.2014, 16:35
For blind programmers using text editors like Vim, the command line is in most cases the only convinient work environment. On the other hand some tasks are not possible on a raw tty, therefore a GUI is necessary. Copying text between a tty and a X session is more or less a pain. In this short article, I'll describe xclip and some convenient ways to use it with Vim / ZSH / GNU screen.
First of all, you should install it, e.g. through using
apt-get install xclip. To copy
hi to your clipboard, try:
echo "hi" | xclip -d :0
You can view the contents of your clipboard using
xclip -o :0 -i
You can of course also copy files into the clipboard to used e.g. the filtering capabilities of a shell but the convenience of GUI file browsers, but for this I advice you to read
If you use the ZSH and want to save some typing, use The following to set up a alias in your
alias -g CLIP='xclip -d :0 -selection clipboard'
You can then easily execute:
echo "hi" | CLIP
Or, if you want to save you quoting trouble on the shell, just invoke "
CLIP" alone, paste your content, press return and
I guess you also want to use the other way around. In Vim, you can paste text from the GUI when you add the following to your
com Paste :call CopyX() func! CopyX() exe ":s/$/\r/g" exe ":.!xclip -selection clipboard -d :0 -o" endfunc
:Paste will then paste text from the X clipboard to your Vim buffer below the current line.
You can also use the clipboard from GNU screen. The following is based on a blog article. and uses instead xclip. Put the following into your
# read and write screen clipboard to X clipboard. bind > eval writebuf "exec sh -c 'xclip -d :0 -selection clipboard < /tmp/.screen-exchange'" bind < eval "exec sh -c 'xclip -selection clipboard -o >/tmp/.screen-exchange'" readbuf
Then you can use
< to easily get the contents into or out of the screen clipboard buffer.