Every now and then I want to diff two random things (like a source-code vs some code I find online).

I could obviously create two files locally and diff them, - but I was wondering if there was a way to open Vimdiff with two empty documents (not to be saved anywhere); where I could copy/paste the text in to diff them quickly and efficiently.

If I just write vimdiff then I just get an empty vim-editor.

1 Answer 1


You can diff two unwritten buffers:

  • Open vim (or open a new tab in you current vim instance)
  • Put your current code in one buffer or open an existing file (:e ./mySourceFile)
  • Split your screen with :sp or ctrl+wv
  • Open a new buffer (:e)
  • Put the new code you want to diff in this new buffer
  • And make a diff between the two buffers with :windo diffthis
  • If you update one of the buffers update the diff with :diffupdate
  • When you're done use :diffoff!


  • +1 this is also useful to vimdiff two already opened copies of a file
    – CervEd
    Jan 8, 2022 at 12:25
  • 1
    if you use the vimdiff command to open vim you can skip the :windo
    – rodvlopes
    Feb 16, 2022 at 13:35

Your Answer

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

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