Home Explore Blog CI



neovim

5th chunk of `runtime/doc/diff.txt`
677e8b0fcc69a51acfdce2c7401367b23cfb2875e57226770000000100000cac
 from the other buffer.

To be able to get those lines from another buffer in a [range] it's allowed to
use the last line number plus one.  This command gets all diffs from the other
buffer: >

	:1,$+1diffget

Note that deleted lines are displayed, but not counted as text lines.  You
can't move the cursor into them.  To fill the deleted lines with the lines
from another buffer use ":diffget" on the line below them.
								*E787*
When the buffer that is about to be modified is read-only and the autocommand
that is triggered by |FileChangedRO| changes buffers the command will fail.
The autocommand must not change buffers.

The [bufspec] argument above can be a buffer number, a pattern for a buffer
name or a part of a buffer name.  Examples:

	:diffget		Use the other buffer which is in diff mode
	:diffget 3		Use buffer 3
	:diffget v2		Use the buffer which matches "v2" and is in
				diff mode (e.g., "file.c.v2")

==============================================================================
5. Diff options						*diff-options*

Also see |'diffopt'| and the "diff" item of |'fillchars'|.

					    *diff-slow* *diff_translations*
For very long lines, the diff syntax highlighting might be slow, especially
since it tries to match all different kind of localisations. To disable
localisations and speed up the syntax highlighting, set the global variable
g:diff_translations to zero: >

    let g:diff_translations = 0
<
After setting this variable, reload the syntax script: >

    set syntax=diff
<


FINDING THE DIFFERENCES					*diff-diffexpr*

The 'diffexpr' option can be set to use something else than the internal diff
support or the standard "diff" program to compare two files and find the
differences.

When 'diffexpr' is empty, Vim uses this command to find the differences
between file1 and file2: >

	diff file1 file2 > outfile

The ">" is replaced with the value of 'shellredir'.

The output of "diff" must be a normal "ed" style diff or a unified diff.  A
context diff will NOT work.  For a unified diff no context lines can be used.
Using "diff -u" will NOT work, use "diff -U0".

This example explains the format that Vim expects for the "ed" style diff: >

	1a2
	> bbb
	4d4
	< 111
	7c7
	< GGG
	---
	> ggg

The "1a2" item appends the line "bbb".
The "4d4" item deletes the line "111".
The "7c7" item replaces the line "GGG" with "ggg".

When 'diffexpr' is not empty, Vim evaluates it to obtain a diff file in the
format mentioned.  These variables are set to the file names used:

	v:fname_in		original file
	v:fname_new		new version of the same file
	v:fname_out		where to write the resulting diff file

Additionally, 'diffexpr' should take care of "icase" and "iwhite" in the
'diffopt' option.  'diffexpr' cannot change the value of 'lines' and
'columns'.

The advantage of using a function call without arguments is that it is faster,
see |expr-option-function|.

Example (this does almost the same as 'diffexpr' being empty): >

	set diffexpr=MyDiff()
	function MyDiff()
	   let opt = ""
	   if &diffopt =~ "icase"
	     let opt = opt .. "-i "
	   endif
	   if &diffopt =~ "iwhite"
	     let opt = opt .. "-b "
	   endif
	   silent execute "!diff -a --binary " .. opt .. v:fname_in .. " " .. v:fname_new ..
		\  "

Title: Diff Options and Custom Diff Expressions
Summary
This section details diff options, including using `:1,$+1diffget` to get all diffs from another buffer and handling read-only buffers. It explains how to speed up diff syntax highlighting by disabling localizations, and it discusses using custom diff expressions via the 'diffexpr' option. It also provides an example function for setting 'diffexpr', demonstrating how to incorporate 'icase' and 'iwhite' options.