Home Explore Blog CI



neovim

2nd chunk of `runtime/doc/diff.txt`
15d1286fc3007c67fce1993e5aa235a23dbac16dd09d65ae0000000100000fa4

:difft[his]	Make the current window part of the diff windows.  This sets
		the options as for "nvim -d".

:diffp[atch] {patchfile}			 *E816* *:diffp* *:diffpatch*
		Use the current buffer, patch it with the diff found in
		{patchfile} and open a buffer on the result.  This sets the
		options as for "nvim -d".
		{patchfile} can be in any format that the "patch" program
		understands or 'patchexpr' can handle.
		Note that {patchfile} should only contain a diff for one file,
		the current file.  If {patchfile} contains diffs for other
		files as well, the results are unpredictable.  Vim changes
		directory to /tmp to avoid files in the current directory
		accidentally being patched.  But it may still result in
		various ".rej" files to be created.  And when absolute path
		names are present these files may get patched anyway.

To make these commands use a vertical split, prepend |:vertical|.  Examples: >

	:vert diffsplit main.c~
	:vert diffpatch /tmp/diff

If you always prefer a vertical split include "vertical" in 'diffopt'.

							*E96*
There can be up to eight buffers with 'diff' set.

Since the option values are remembered with the buffer, you can edit another
file for a moment and come back to the same file and be in diff mode again.

							*:diffo* *:diffoff*
:diffo[ff]	Switch off diff mode for the current window.  Resets related
		options also when 'diff' was not set.

:diffo[ff]!	Switch off diff mode for the current window and in all windows
		in the current tab page where 'diff' is set.  Resetting
		related options only happens in a window that has 'diff' set,
		if the current window does not have 'diff' set then no options
		in it are changed.
		Hidden buffers are also removed from the list of diff'ed
		buffers.

The `:diffoff` command resets the relevant options to the values they had when
using `:diffsplit`, `:diffpatch`, `:diffthis`. or starting Vim in diff mode.
When using `:diffoff` twice the last saved values are restored.
Otherwise they are set to their default value:

	'diff'		off
	'scrollbind'	off
	'cursorbind'	off
	'scrollopt'	without "hor"
	'wrap'		on, or leave as-is if 'diffopt' includes "followwrap"
	'foldmethod'	"manual"
	'foldcolumn'	0

'foldenable' will most-likely be reset to off.  That is when 'foldmethod' is
restored to "manual".  The folds themselves are not cleared but they should
not show up, resetting 'foldenable' is the best way to do that.

==============================================================================
2. Viewing diffs						*view-diffs*

The effect is that the diff windows show the same text, with the differences
highlighted.  When scrolling the text, the 'scrollbind' option will make the
text in other windows to be scrolled as well.  With vertical splits the text
should be aligned properly.

The alignment of text will go wrong when:
- 'wrap' is on, some lines will be wrapped and occupy two or more screen
  lines
- folds are open in one window but not another
- 'scrollbind' is off
- changes have been made to the text
- "filler" is not present in 'diffopt', deleted/inserted lines makes the
  alignment go wrong

All the buffers edited in a window where the 'diff' option is set will join in
the diff.  This is also possible for hidden buffers.  They must have been
edited in a window first for this to be possible.  To get rid of the hidden
buffers use `:diffoff!`.

					*:DiffOrig* *diff-original-file*
Since 'diff' is a window-local option, it's possible to view the same buffer
in diff mode in one window and "normal" in another window.  It is also
possible to view the changes you have made to a buffer since the file was
loaded.  Since Vim doesn't allow having two buffers for the same file, you
need another buffer.  This command is useful: >
	 command DiffOrig vert new | set buftype=nofile | read ++edit # | 0d_
		\ | diffthis | wincmd p | diffthis
Use ":DiffOrig" to see the differences
between the current buffer and the file it was loaded from.

A buffer that is unloaded cannot be used

Title: Diff Mode Commands and Viewing Diffs
Summary
This section describes the `:difft`, `:diffpatch`, and `:diffoff` commands to control diff mode. It explains how `:difft` makes the current window part of the diff, `:diffpatch` applies a patch file to the current buffer, and `:diffoff` switches off diff mode. It also covers viewing diffs, potential alignment issues, and using the `:DiffOrig` command to compare the current buffer with the original file.