Real-time vimdiff Without Saving Files to Compare Clipboard Content
📝 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 noswapfile
disables vim’s swap files for these buffersvnew
creates a new vertical split windowwindo setlocal nobuflisted buftype=nofile noswapfile
sets both windows to not appear in buffer list and not be associated with filesset diffopt=filler,iwhite
configures diff to show filler lines and ignore whitespace differenceswindo diffthis
activates diff mode in both windowswincmd h
moves cursor to the left windowautocmd TextChanged,TextChangedI * diffupdate
automatically 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.