While it has already been answered how to start the diff, it's also important how to stop it in all windows. For completeness, I repeat the comment from @Bernhard.
Start and Stop Diff of two files opened in 2 Windows (works in both, vertical and horizontal split):
:windo diffthis
:windo diffoff
this can be shortened to either
:windo difft
:windo diffo
or
:windo difft
:diffo!
Be aware that opened windows for showing plugin content lead to issues. So close stuff like NERDtree, minibufexplorer++ etc before.
Custom commands:
To ease up things you can add custom commands to your ~/.vimrc
:
command! Difft [ClosePluginWindow |] windo diffthis
command! Diffo windo diffoff
with [ClosePluginWindow |]
being optional to close plugin windows you usually use. For NERDtree e.g. this would be NERDTreeClose |
.
Credits go to @cxw and @Jordi Freixa.
vimdiff file1.txt file2.txt
(see below) – Eduardo Cuomo Jun 19 '17 at 18:22:e
). With that knowledge it's pretty obvious that you can open the file you want to compare when navigating to the other site. Funny, how an answer that allegedly doesn't answer the question was accepted and currently is the highest voted one. – maxschlepzig Feb 17 '22 at 21:17:split
or:vsplit
as well as per your steps (just for other options). In either case, once one has their two windows open in vim, run:diffthis
in each window for a typical side by side diff. Usediffoff
to disable diff mode (acts on the active window, so if only run once, the other window is still selected for diffing, so just:e file3.txt
and then:diffthis
to diff the original window with file1.txt to file3.txt). Using:diffthis
activates scroll lock and between the windows and highlights differences. – Chris Jun 08 '23 at 00:25:w
in some form. To know you are looking at 'as per the file on disk' i suggest usingvim -O file1 file2
– Chris Jun 08 '23 at 00:29vimdiff file1 file2
ornvim -d file1 file2
are even better options. – Chris Jun 08 '23 at 00:41