Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

The two clipboards in Linux

📅 2017-Jan-18 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ clipboard, linux ⬩ 📚 Archive

If you have come to Linux from Windows or Mac, you might have observed some strange behavior when selecting, copying or pasting content. This confusing behavior is caused because there are two clipboards in Linux. In X Windows jargon, these clipboards are called selections.

There is even older concept called the cutbuffer in X, which is deprecated and we will not discuss that here.

PRIMARY

Any text or content you mark by selecting with the mouse cursor is automatically copied to this PRIMARY selection or X Window selection or just selection. When you middle-click the mouse cursor at a destination location, the content of the PRIMARY selection is pasted there.

CLIPBOARD

The CLIPBOARD selection works similar to the Windows or Mac clipboard. Windowing environments might even have a clipboard manager which can maintain a historical list of the entries of this CLIPBOARD selection.

Text or content is copied to CLIPBOARD when you use the cut/copy menu items, Ctrl+C/Ctrl+X keyboard shortcuts. Content from the CLIPBOARD selection is pasted at the destination where you use the paste menu item or use Ctrl+V keyboard shortcut.

Syncing selections

Well written applications are supposed to keep PRIMARY and CLIPBOARD in sync, so that the user has no surprises. Not all applications do that, so it is useful to know the above information. When the PRIMARY and CLIPBOARD are not synced, a new user to Linux can be surprised. They select text using the mouse and expect to be able to paste it using Ctrl+V.

Thankfully, clipboard managers of KDE and GNOME have options to keep both PRIMARY and CLIPBOARD in sync that you can enable if you want such synced behavior.

Reference


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧