Quick and Dirty Text Diffing
Chris posted about something I often find myself needing: how do I do a quick diff on two sets of text?
He shows how to do it with GitHub Gists. He also links to the online tool Diffchecker, which is what I usually use for a quick and easy diff.
But a part of me has always wanted a native tool doing something like this. So I asked on Twitter what folks do.
A lot of the replies came in the form of CLI commands to diff two existing files.
@johncjago suggested the built-in diff
:
diff file1.txt file2.txt
@pawelgrzybek suggested vscode’s CLI tool (hats off to him for having a blog post on the matter).
code --diff file1.txt file2.txt
And @geoff_l suggested the nuclear option (or the enlightened option, however you look at it): vim
.
vim -d file1.txt file2.txt
All great suggestions.
What I really want, though, is a solution that lets me diff two pieces of text that aren’t yet files. Copy/paste some text into pane 1, copy/paste some text into pane 2, and hit the big red “DIFF” button.
@hybrid_alex suggested Kaledeiscope (which I’ve always thought to be just a beautiful Mac app) and, turns out, you can diff text from the clipboard!
Copy/paste two different sets of text and you’ve got the Kaleidoscope diff tool at your disposal.
Granted Kaleidoscope costs money, but it’s a great looking app, has lots of other features (including image diffing), and has been around forever, so I thought that would be my solution.
Then along came @MRWweb who suggested looking into an extension in vscode. Turns out, there’s a great extension called Partial Diff which allows you to diff snippets of text — from the clipboard, from saved files, from unsaved files, it’s quite versatile — and compare them right inside vscode.
What I love about this tool is it lets me do exactly what was in my head:
- Open a pane and paste some text.
- Open another pane and paste some text.
- Hit “Diff”
You can see here I have my two unsaved tabs of text in vscode.
I then right click and get a menu with Partial Diff’s options (my favorite is the “Compare Text in Visible Editors”).
Then a new tab opens showing my diff (similar to what you’d see if you can code --diff
from the CLI).
It’s a great solution that gains an upperhand by being integrated right into my code editor.
Update 2022-05-19
Turns out, you don’t even need an extension to do this!
@chrisofspades came late to the party noting that you can do ephemeral text diffing in vscode without any extensions at all.
- Copy/paste to untitled doc1
- Copy/paste to untitled doc2
CMD + Shift + P
“Compare active file with…” and select doc 1.