Real-time vimdiff Without Saving Files to Compare Clipboard Content
Paste text to compare in vimdiff without creating files.
📝 From my notes: living personal cheatsheets.
I often want to compare a few lines of text without saving them to files.
Here’s a command that creates a two-pane vimdiff where you can paste text and see differences highlighted in real-time:
Here’s what each part does:
set noswapfiledisables vim’s swap files for these buffersvnewcreates a new vertical split windowwindo setlocal nobuflisted buftype=nofile noswapfilesets both windows to not appear in buffer list and not be associated with filesset diffopt=filler,iwhiteconfigures diff to show filler lines and ignore whitespace differenceswindo diffthisactivates diff mode in both windowswincmd hmoves cursor to the left windowautocmd TextChanged,TextChangedI * diffupdateautomatically updates diff highlighting whenever text changes. Otherwise you’d need to manually run:diffupdate
I added it as an alias to my shell configuration:
Now I can run dp (for diff paste) and get instant diffing.
Extra: VS Code equivalent
There’s an equivalent feature in Visual Studio Code: press ⌘+Shift+P to open the command palette and search for “File: Compare New Untitled Text Files”.
Search for workbench.files.action.compareNewUntitledTextFiles to set up a keybinding for it.