How to restore plain text clipboard functionality with xclip on Linux desktops
With xclip, you can restore the plain text functionality in copy / paste behavior of the desktop clipboard. This will effectively remove any text formatting, images, embedded URL links, etc.
You may need to install the xclip package first since it's not a typical default package for most Linux distributions.
sudo apt install xclip
After completing the xclip install, create a shell script that is available in your user $PATH environment (i.e. in ~/bin or ~/.local/bin). Don't forget to apply the execution bit to the file so that you're able to run it.
chmod +x clipboard.sh
The contents of the shell script should include the following:
#!/bin/bash
xclip -o | xclip -selection clipboard
Instead, if you would prefer to eliminate beginning and trailing white spaces, you can use the following.
#!/bin/bash
xclip -o | awk '{ gsub(/^[ \t]+|[ \t]+$/, ""); print }' | sed -z 's/\(.*\)\n$/\1/' | xclip -selection clipboard
Now open your keyboard shortcut settings and create a custom shortcut that will launch the script. I highly recommend using something other than “Ctrl-C” since overriding this command could affect the functionality of other programs (i.e. VIM or KeePassXC.) Use Ctrl-Shift-C instead.
[Return to top]