14

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.

Zeth
  • 405
  • 3
  • 12

1 Answers1

25

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!

See

Rohan Ghige
  • 219
  • 1
  • 11
statox
  • 49,782
  • 19
  • 148
  • 225