How to create a diff of the current text and the clipboard?

It could result in a vertical split showing the clipboard content, and a normal diff between them. Opening a vertical split, pasting and diffing should work, but there are the commands :diffsplit and :diffthis, so I feel I may be missing something.

  • 1. What do you call "the clipboard"? 2. What did you try?
    – romainl
    Mar 20 at 19:33
  • i mean the system clipboard, like when cutting elsewhere with Ctrl-C and pasting with pin vim. I tried to manually create two documents to diff, but that is more like a workaround, not a solution. Mar 21 at 21:39
  • Hi @Volker, I try to close the question. Do you still have one aspect of your question that is not answered and if so which one? Otherwise I'll be glad if you could accept one answer to allow the question to rest :-) Mar 29 at 21:10

1 Answer 1


You could apply a variant of the Diff recipe:

function! DiffClipboard()
    let ft=&ft
    vertical new
    setlocal bufhidden=wipe buftype=nofile nobuflisted noswapfile
    silent 0d_
    setlocal nomodifiable
    execute "set ft=" . ft
    wincmd p
command! DiffClipboard call DiffClipboard()
  • 1
    Consider normal! p or just put
    – D. Ben Knoble
    Mar 21 at 13:26
  • should that be :0put +? Mar 21 at 15:41
  • Could be but to make sure the number of the line :1put + and keep the silent 0d_ works better for me. On Windows the clipboard is either " or * with set unnamed. Why do you prefer + over "? Mar 21 at 15:59
  • Did you mean "either * or +"?
    – romainl
    Mar 22 at 10:30
  • You are right * or + Mar 22 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.