I've have two files opened. They are opened in vertical mode, next to next. Can I instantly diff these two files without leaving or closing Vim ?
Asked
Active
Viewed 2.5k times
4 Answers
198
To begin diffing on all visible windows:
:windo diffthis
which executes :diffthis
on each window.
To end diff mode:
:diffoff!
(The !
makes diffoff
apply to all windows of the current tab - it'd be nice if diffthis
had the same feature, but it doesn't.)

Nefrubyr
- 6,936
- 2
- 29
- 20
-
The `:windo` command makes it even better. Thanks. I'll will map it to make it easier. – Fatih Arslan Dec 08 '10 at 10:21
-
2That's good answer, but note that minibufexplorer window should be closed before this operation, if opened. Otherwise diff shows incorrect results. – baldrs Jul 30 '14 at 13:28
-
1One can use an alias`:windo difft[this]`. Ref: `:help diff` – DmitrySandalov Apr 22 '15 at 18:04
28
in each of the windows you want to diff type:
:diffthis
If you want to diff all of the open windows, you can do:
:windo diffthis
(windo
will apply the command to all open windows)

Nathan Fellman
- 122,701
- 101
- 260
- 319
10
Following up on the earlier answers,
:windo difft
(short fordiffthis
) will start diff mode in all the open windows.:windo diffo
(short fordiffoff
) will stop diff mode in all the open windows.
I have the following mappings in my vimrc
to make it easier:
command! Difft windo diffthis
command! Diffo windo diffoff

cxw
- 16,685
- 2
- 45
- 81
6
Following on the earlier answers I adapted the mapping provided by @cxw. The following mapping automatically closes NERDTree and diffs the open windows. It does not matter if NERDTree is closed, it works the same way. I do this quite often so it saved me quite some time.
command! Difft NERDTreeClose | windo diffthis

Wolfson
- 1,187
- 17
- 22

Jordi Freixa
- 61
- 1
- 3