Home Explore Blog CI



neovim

6th chunk of `runtime/doc/diff.txt`
b1e4b5a80705e21d7f05353d383ca8225cdc90335b8630ea000000010000084b
 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 ..
		\  " > " .. v:fname_out
	   redraw!
	endfunction

The "-a" argument is used to force comparing the files as text, comparing as
binaries isn't useful.  The "--binary" argument makes the files read in binary
mode, so that a CTRL-Z doesn't end the text on DOS.

The `redraw!` command may not be needed, depending on whether executing a
shell command shows something on the display or not.

If the 'diffexpr' expression starts with s: or |<SID>|, then it is replaced
with the script ID (|local-function|). Example: >
		set diffexpr=s:MyDiffExpr()
		set diffexpr=<SID>SomeDiffExpr()
Otherwise, the expression is evaluated in the context of the script where the
option was set, thus script-local items are available.

						*E810* *E97*
Vim will do a test if the diff output looks alright.  If it doesn't, you will
get an error message.  Possible causes:
-  The "diff" program cannot be executed.
-  The "diff" program doesn't produce normal "ed" style diffs (see above).
-  The 'shell' and associated options are not set correctly.  Try if filtering
   works with a command like ":!sort".
-  You are using 'diffexpr' and it doesn't

Title: Custom Diff Expressions in Vim (Continued)
Summary
This section further details custom diff expressions in Vim. It explains how Vim evaluates 'diffexpr' to obtain a diff file and which variables are set for file names. It also shows an example function for setting 'diffexpr', demonstrating how to incorporate 'icase' and 'iwhite' options. Finally, it explains the potential errors and causes.