22

I know you would normally enter into vimdiff mode from the terminal with vimdiff file1 file2. However, I frequently find myself already in vim with multiple different splits, and I'd like to run vimdiff on two specific splits, and then turn vimdiff off.

How would I go about this?

N.B. there might be other splits in my vim session that I don't want to be comparing. So I might have 4 vertical splits and I want to run vimdiff on split 1 with split 3, look at some differences, and then turn the diff off.

Aeroblop
  • 323
  • 2
  • 4

2 Answers2

24

The command is called :diffthis. It must be executed in every window you want to add to the comparison.

The inverse is :diffoff which exits diff mode in the current window. To exit diff mode in all applicable windows add a bang: :diffoff!.

B Layer
  • 19,834
  • 2
  • 30
  • 57
Matt
  • 20,685
  • 1
  • 11
  • 24
2

Noting that two :diffthis commands ought to be issued with the existing two-split view, here's a quick Autohotkey snippet that does the trick - it simply emulates key-input to the Vim window by issuing :diffthis twice.

            send :diffthis
            send {enter}
            send ^w
            send w
            send :diffthis
            send {enter}

Looking forward to a native Vimscript/Lua-based solution.


Correction: :windo diffthis does the trick!

Kudos to Christian Brabandt.

Note, :windo diffoff achieves the same function as :diffoff!.

llinfeng
  • 352
  • 2
  • 14