Diff two tabs in Vim

VimDiffTabsVimdiffBuffer

Vim Problem Overview


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.

Vim Solutions


Solution 1 - Vim

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.

Solution 2 - Vim

I would suggest trying :diffthis or :diffsplit

Solution 3 - Vim

When you have two files opened in vertical splitt, run

:windo diffthis

Solution 4 - Vim

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondavetapleyView Question on Stackoverflow
Solution 1 - VimJanView Answer on Stackoverflow
Solution 2 - VimjoesliceView Answer on Stackoverflow
Solution 3 - VimA BView Answer on Stackoverflow
Solution 4 - VimsnapView Answer on Stackoverflow