123

Scenario: I have opened Vim and pasted some text. I open a second tab with :tabe and paste some other text in there.

Goal: I would like a third tab with a output equivalent to writing both texts to files and opening them with vimdiff.

The closest I can find is "diff the current buffer against a file", but not diffing two open but unsaved buffers.

davetapley
  • 17,000
  • 12
  • 60
  • 86

4 Answers4

193

I suggest opening the second file in the same tab instead of a new one.

Here's what I usually do:

:edit file1
:diffthis
:vnew
:edit file2
:diffthis

The :vnew command splits the current view vertically so you can open the second file there. The :diffthis (or short: :difft) command is then applied to each view.

Aaron Thoma
  • 3,820
  • 1
  • 37
  • 34
Jan
  • 2,480
  • 2
  • 17
  • 19
  • 1
    Fwiw, MacVim doesn't seem to have this by default, but I think you should be able to go to the terminal and type `vimdiff file1.txt file2.txt` and knock yourself out. – ruffin Mar 23 '12 at 14:55
  • 3
    This is awesometastic. The `edit fileN` parts can be replaced with just pasting from the buffer, which lets you diff two chunks of text without pasting each into a tmp file (something that meld lets you do, but visual diff tools on the Mac are lacking in). It worked in MacVim for me out of the box. – yshavit Nov 15 '13 at 16:23
38

I would suggest trying :diffthis or :diffsplit

joeslice
  • 3,454
  • 1
  • 19
  • 24
27

When you have two files opened in vertical splitt, run

:windo diffthis

A B
  • 2,013
  • 2
  • 21
  • 22
2

The content of all tabs are inside the buffers. Look at the buffers:

:buffers

Find the right number for the content which should be diffed with your current tab content.

Open the buffer inside your current tab (f.e. buffer number 4)

:sb 4

Or do for vertical view:

:vertical sb 4

Then you can simple diff the content with

:windo diffthis

If you finished diff analysis you can input:

:windo diffoff
snap
  • 1,598
  • 1
  • 14
  • 21