DEV Community

Mahdi Hosseinpour
Mahdi Hosseinpour

Posted on

Compare Any Two Texts Instantly on Linux (Clipboard + Selection Hack)

One of my most-used features when coding in IntelliJ is “Compare with Clipboard” — super handy when I want to quickly compare a piece of code with its previous version.

But when the text or code was outside IntelliJ, I had to open a diff tool manually or use “Open Blank Diff Window” inside IntelliJ and paste both snippets by hand.

Recently, I found a much simpler way, and I thought it’s worth sharing here 👇

(This explanation is for Linux, but Windows users can easily adapt it or… just ask AI 😉)


🧩 Setup steps:
1️⃣ Install meld program (or another diff tool with CLI support and use it in the script).
2️⃣ Install xsel and xclip packages (wl-clipboard on Wayland).
3️⃣ Save this script anywhere on your system.
4️⃣ Create a global keyboard shortcut that runs the script.
→ Suggested: Meta + Ctrl + Shift + D.


✅ Now you can:

  • Copy the first text snippet.
  • Select the second text snippet.
  • Hit your shortcut.

meld will pop up, showing both texts side by side — clipboard on the right, selected text on the left.

(You can swap f1 and f2 in the script if you prefer the opposite order.)


💡 This quickly became one of my favorite little productivity hacks.
I can compare any two pieces of text on my system without leaving my current window.

If you have similar tricks, I’d love to hear them!

Top comments (0)