vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

diff.txt (24863B)


      1 *diff.txt*	For Vim version 9.2.  Last change: 2026 Feb 14
      2 
      3 
      4 		  VIM REFERENCE MANUAL	  by Bram Moolenaar
      5 
      6 
      7 				*diff* *vimdiff* *gvimdiff* *diff-mode*
      8 This file describes the |+diff| feature: Showing differences between two to
      9 eight versions of the same file.
     10 
     11 The basics are explained in section |08.7| of the user manual.
     12 
     13 1. Starting diff mode		|start-vimdiff|
     14 2. Viewing diffs		|view-diffs|
     15 3. Jumping to diffs		|jumpto-diffs|
     16 4. Copying diffs		|copy-diffs|
     17 5. Diff anchors			|diff-anchors|
     18 6. Diff options			|diff-options|
     19 
     20 ==============================================================================
     21 1. Starting diff mode					*start-vimdiff*
     22 
     23 The easiest way to start editing in diff mode is with the "vimdiff" command.
     24 This starts Vim as usual, and additionally sets up for viewing the differences
     25 between the arguments. >
     26 
     27 	vimdiff file1 file2 [file3 [file4]]
     28 
     29 This is equivalent to: >
     30 
     31 	vim -d file1 file2 [file3 [file4]]
     32 
     33 You may also use "gvimdiff" or "vim -d -g".  The GUI is started then.
     34 You may also use "viewdiff" or "gviewdiff".  Vim starts in readonly mode then.
     35 "r" may be prepended for restricted mode (see |-Z|).
     36 
     37 The second and following arguments may also be a directory name.  Vim will
     38 then append the file name of the first argument to the directory name to find
     39 the file.
     40 
     41 By default an internal diff library will be used.  When 'diffopt' or
     42 'diffexpr' has been set an external "diff" command will be used.  This only
     43 works when such a diff program is available.
     44 
     45 Diffs are local to the current tab page |tab-page|.  You can't see diffs with
     46 a window in another tab page.  This does make it possible to have several
     47 diffs at the same time, each in their own tab page.
     48 
     49 What happens is that Vim opens a window for each of the files.  This is like
     50 using the |-O| argument.  This uses vertical splits.  If you prefer horizontal
     51 splits add the |-o| argument: >
     52 
     53 	vimdiff -o file1 file2 [file3 [file4]]
     54 
     55 If you always prefer horizontal splits include "horizontal" in 'diffopt'.
     56 
     57 In each of the edited files these options are set:
     58 
     59 	'diff'		on
     60 	'scrollbind'	on
     61 	'cursorbind'	on
     62 	'scrollopt'	includes "hor"
     63 	'wrap'		off, or leave as-is if 'diffopt' includes "followwrap"
     64 	'foldmethod'	"diff"
     65 	'foldcolumn'	value from 'diffopt', default is 2
     66 
     67 These options are set local to the window.  When editing another file they are
     68 reset to the global value.
     69 The options can still be overruled from a modeline when re-editing the file.
     70 However, 'foldmethod' and 'wrap' won't be set from a modeline when 'diff' is
     71 set.
     72 See `:diffoff` for an easy way to revert the options.
     73 
     74 The differences shown are actually the differences in the buffer.  Thus if you
     75 make changes after loading a file, these will be included in the displayed
     76 diffs.  You might have to do ":diffupdate" now and then, not all changes are
     77 immediately taken into account, especially when using an external diff
     78 command.
     79 
     80 In your .vimrc file you could do something special when Vim was started in
     81 diff mode.  You could use a construct like this: >
     82 
     83 	if &diff
     84 	   setup for diff mode
     85 	else
     86 	   setup for non-diff mode
     87 	endif
     88 
     89 While already in Vim you can start diff mode in three ways.
     90 
     91 							*E98*
     92 :diffs[plit] {filename}					*:diffs* *:diffsplit*
     93 		Open a new window on the file {filename}.  The options are set
     94 		as for "vimdiff" for the current and the newly opened window.
     95 		Also see 'diffexpr'.
     96 
     97 							*:difft* *:diffthis*
     98 :difft[his]	Make the current window part of the diff windows.  This sets
     99 		the options like for "vimdiff".
    100 
    101 :diffp[atch] {patchfile}			 *E816* *:diffp* *:diffpatch*
    102 		Use the current buffer, patch it with the diff found in
    103 		{patchfile} and open a buffer on the result.  The options are
    104 		set as for "vimdiff".
    105 		{patchfile} can be in any format that the "patch" program
    106 		understands or 'patchexpr' can handle.
    107 		Note that {patchfile} should only contain a diff for one file,
    108 		the current file.  If {patchfile} contains diffs for other
    109 		files as well, the results are unpredictable.  Vim changes
    110 		directory to /tmp to avoid files in the current directory
    111 		accidentally being patched.  But it may still result in
    112 		various ".rej" files to be created.  And when absolute path
    113 		names are present these files may get patched anyway.
    114 		Using the "patch" command is not allowed in |restricted-mode|.
    115 
    116 To make these commands use a vertical split, prepend |:vertical|.  Examples: >
    117 
    118 	:vert diffsplit main.c~
    119 	:vert diffpatch /tmp/diff
    120 
    121 If you always prefer a vertical split include "vertical" in 'diffopt'.
    122 
    123 							*E96*
    124 There can be up to eight buffers with 'diff' set.
    125 
    126 Since the option values are remembered with the buffer, you can edit another
    127 file for a moment and come back to the same file and be in diff mode again.
    128 
    129 							*:diffo* *:diffoff*
    130 :diffo[ff]	Switch off diff mode for the current window.  Resets related
    131 		options also when 'diff' was not set.
    132 
    133 :diffo[ff]!	Switch off diff mode for the current window and in all windows
    134 		in the current tab page where 'diff' is set.  Resetting
    135 		related options only happens in a window that has 'diff' set,
    136 		if the current window does not have 'diff' set then no options
    137 		in it are changed.
    138 		Hidden buffers are also removed from the list of diff'ed
    139 		buffers.
    140 
    141 The `:diffoff` command resets the relevant options to the values they had when
    142 using `:diffsplit`, `:diffpatch`, `:diffthis`, or starting Vim in diff mode.
    143 When using `:diffoff` twice the last saved values are restored.
    144 Otherwise they are set to their default value:
    145 
    146 	'diff'		off
    147 	'scrollbind'	off
    148 	'cursorbind'	off
    149 	'scrollopt'	without "hor"
    150 	'wrap'		on, or leave as-is if 'diffopt' includes "followwrap"
    151 	'foldmethod'	"manual"
    152 	'foldcolumn'	0
    153 
    154 'foldenable' will most-likely be reset to off.  That is when 'foldmethod' is
    155 is restored to "manual".  The folds themselves are not cleared but they should
    156 not show up, resetting 'foldenable' is the best way to do that.
    157 
    158 ==============================================================================
    159 2. Viewing diffs						*view-diffs*
    160 
    161 The effect is that the diff windows show the same text, with the differences
    162 highlighted.  When scrolling the text, the 'scrollbind' option will make the
    163 text in other windows to be scrolled as well.  With vertical splits the text
    164 should be aligned properly.
    165 
    166 The alignment of text will go wrong when:
    167 - 'wrap' is on, some lines will be wrapped and occupy two or more screen
    168   lines
    169 - folds are open in one window but not another
    170 - 'scrollbind' is off
    171 - changes have been made to the text
    172 - "filler" is not present in 'diffopt', deleted/inserted lines makes the
    173   alignment go wrong
    174 
    175 All the buffers edited in a window where the 'diff' option is set will join in
    176 the diff.  This is also possible for hidden buffers.  They must have been
    177 edited in a window first for this to be possible.  To get rid of the hidden
    178 buffers use `:diffoff!`.
    179 
    180 					*:DiffOrig* *diff-original-file*
    181 Since 'diff' is a window-local option, it's possible to view the same buffer
    182 in diff mode in one window and "normal" in another window.  It is also
    183 possible to view the changes you have made to a buffer since the file was
    184 loaded.  Since Vim doesn't allow having two buffers for the same file, you
    185 need another buffer.  This command is useful: >
    186 	 command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_
    187 		\ | diffthis | wincmd p | diffthis
    188 (this is in |defaults.vim|).  Use ":DiffOrig" to see the differences between
    189 the current buffer and the file it was loaded from.
    190 
    191 A buffer that is unloaded cannot be used for the diff.  But it does work for
    192 hidden buffers.  You can use ":hide" to close a window without unloading the
    193 buffer.  If you don't want a buffer to remain used for the diff do ":set
    194 nodiff" before hiding it.
    195 
    196 						*:dif* *:diff* *:diffupdate*
    197 :dif[fupdate][!]		Update the diff highlighting and folds.
    198 
    199 Vim attempts to keep the differences updated when you make changes to the
    200 text.  This mostly takes care of inserted and deleted lines.  Changes within a
    201 line and more complicated changes do not cause the differences to be updated.
    202 To force the differences to be updated use: >
    203 
    204 	:diffupdate
    205 
    206 If the ! is included Vim will check if the file was changed externally and
    207 needs to be reloaded.  It will prompt for each changed file, like `:checktime`
    208 was used.
    209 
    210 Vim will show filler lines for lines that are missing in one window but are
    211 present in another.  These lines were inserted in another file or deleted in
    212 this file.  Removing "filler" from the 'diffopt' option will make Vim not
    213 display these filler lines.
    214 
    215 
    216 Folds are used to hide the text that wasn't changed.  See |folding| for all
    217 the commands that can be used with folds.
    218 
    219 The context of lines above a difference that are not included in the fold can
    220 be set with the 'diffopt' option.  For example, to set the context to three
    221 lines: >
    222 
    223 	:set diffopt=filler,context:3
    224 
    225 
    226 The diffs are highlighted with these groups:
    227 
    228 |hl-DiffAdd|	DiffAdd		Added (inserted) lines.  These lines exist in
    229 				this buffer but not in another.
    230 |hl-DiffChange|	DiffChange	Changed lines.
    231 |hl-DiffText|	DiffText	Changed text inside a Changed line.  Exact
    232 				behavior depends on the `inline:` setting in
    233 				'diffopt'.
    234 				With `inline:` set to "simple", Vim finds the
    235 				first character that is different, and the
    236 				last character that is different (searching
    237 				from the end of the line).  The text in
    238 				between is highlighted.  This means that parts
    239 				in the middle that are still the same are
    240 				highlighted anyway.  The 'diffopt' flags
    241 				"iwhite" and "icase" are used here.
    242 				With `inline:` set to "char" or "word", Vim
    243 				uses the internal diff library to perform a
    244 				detailed diff between the changed blocks and
    245 				highlight the exact difference between the
    246 				two.  Will respect any 'diffopt' flag that
    247 				affects internal diff.
    248 				Not used when `inline:` is set to "none".
    249 |hl-DiffTextAdd|  DiffTextAdd	Added text inside a Changed line.  Similar to
    250 				DiffText, but used when there is no
    251 				corresponding text in other buffers.  Not used
    252 				when `inline:` is set to "simple" or "none".
    253 |hl-DiffDelete|	DiffDelete	Deleted lines.  Also called filler lines,
    254 				because they don't really exist in this
    255 				buffer.
    256 
    257 ==============================================================================
    258 3. Jumping to diffs					*jumpto-diffs*
    259 
    260 Two commands can be used to jump to diffs:
    261 								*[c*
    262 	[c		Jump backwards to the previous start of a change.
    263 			When a count is used, do it that many times.
    264 								*]c*
    265 	]c		Jump forwards to the next start of a change.
    266 			When a count is used, do it that many times.
    267 
    268 It is an error if there is no change for the cursor to move to.
    269 
    270 ==============================================================================
    271 4. Diff copying			*copy-diffs* *E99* *E100* *E101* *E102* *E103*
    272 								*merge*
    273 There are two commands to copy text from one buffer to another.  The result is
    274 that the buffers will be equal within the specified range.
    275 
    276 							*:diffg* *:diffget*
    277 :[range]diffg[et] [bufspec]
    278 		Modify the current buffer to undo difference with another
    279 		buffer.  If [bufspec] is given, that buffer is used.  If
    280 		[bufspec] refers to the current buffer then nothing happens.
    281 		Otherwise this only works if there is one other buffer in diff
    282 		mode.
    283 		See below for [range].
    284 
    285 						*:diffpu* *:diffput* *E793*
    286 :[range]diffpu[t] [bufspec]
    287 		Modify another buffer to undo difference with the current
    288 		buffer.  Just like ":diffget" but the other buffer is modified
    289 		instead of the current one.
    290 		When [bufspec] is omitted and there is more than one other
    291 		buffer in diff mode where 'modifiable' is set this fails.
    292 		See below for [range].
    293 
    294 							*do*
    295 [count]do	Same as ":diffget" without range.  The "o" stands for "obtain"
    296 		("dg" can't be used, it could be the start of "dgg"!).  Note:
    297 		this doesn't work in Visual mode.
    298 		If you give a [count], it is used as the [bufspec] argument
    299 		for ":diffget".
    300 
    301 							*dp*
    302 [count]dp	Same as ":diffput" without range.  Note: this doesn't work in
    303 		Visual mode.
    304 		If you give a [count], it is used as the [bufspec] argument
    305 		for ":diffput".
    306 
    307 
    308 When no [range] is given, the diff at the cursor position or just above it is
    309 affected.  There can be deleted lines below the last line of the buffer.  When
    310 the cursor is on the last line in the buffer and there is no diff above this
    311 line, and no [range] is given, the diff below the cursor position will be used
    312 instead.
    313 
    314 When [range] is used, Vim tries to only put or get the specified lines.  When
    315 there are deleted lines, they will be used if they are between the lines
    316 specified by [range].
    317 
    318 To be able to put or get those lines to/from another buffer in a [range] it's
    319 allowed to use 0 and the last line number plus one.  This command gets all
    320 diffs from the other buffer: >
    321 
    322 	:0,$+1diffget
    323 
    324 Note that deleted lines are displayed, but not counted as text lines.  You
    325 can't move the cursor into them.  To fill the deleted lines with the lines
    326 from another buffer use ":diffget" on the line below them.
    327 								*E787*
    328 When the buffer that is about to be modified is read-only and the autocommand
    329 that is triggered by |FileChangedRO| changes buffers the command will fail.
    330 The autocommand must not change buffers.
    331 
    332 The [bufspec] argument above can be a buffer number, a pattern for a buffer
    333 name or a part of a buffer name.  Examples:
    334 
    335 	:diffget		Use the other buffer which is in diff mode
    336 	:diffget 3		Use buffer 3
    337 	:diffget v2		Use the buffer which matches "v2" and is in
    338 				diff mode (e.g., "file.c.v2")
    339 
    340 ==============================================================================
    341 5. Diff anchors						*diff-anchors*
    342 
    343 Diff anchors allow you to control where the diff algorithm aligns and
    344 synchronize text across files.  Each anchor matches each other in each file,
    345 allowing you to control the output of a diff.
    346 
    347 This is useful when a change involves complicated edits.  For example, if a
    348 function was moved to another location and further edited.  By default, the
    349 algorithm aims to create the smallest diff, which results in that entire
    350 function being considered to be deleted and added on the other side, making it
    351 hard to see what the actual edit on it was.  You can use diff anchors to pin
    352 that function so the diff algorithm will align based on it.
    353 
    354 To use it, set anchors using 'diffanchors' which is a comma-separated list of
    355 {address} in each file, and then add "anchor" to 'diffopt'.  Internally, Vim
    356 splits each file up into sections split by the anchors.  It performs the diff
    357 on each pair of sections separately before merging the results back.
    358 
    359 Setting 'diffanchors' will update the diff immediately.  If an anchor is tied
    360 to a mark, and you change what the mark is pointed to, you need to manually
    361 call |:diffupdate| afterwards to get the updated diff results.
    362 
    363 Example:
    364 
    365 Let's say we have the following files, side-by-side.  We are interested in the
    366 change that happened to the function `foo()`, which was both edited and moved.
    367 
    368 File A: >
    369 	int foo() {
    370 	    int n = 1;
    371 	    return n;
    372 	}
    373 
    374 	int g = 1;
    375 
    376 	int bar(int a) {
    377 	    a *= 2;
    378 	    a += 3;
    379 	    return a;
    380 	}
    381 <File B: >
    382 	int bar(int a) {
    383 	    a *= 2;
    384 	    a += 3;
    385 	    return a;
    386 	}
    387 
    388 	int foo() {
    389 	    int n = 999;
    390 	    return n;
    391 	}
    392 
    393 	int g = 1;
    394 <
    395 A normal diff will usually align the diff result as such: >
    396 
    397 	int foo() {     |----------------
    398 	    int n = 1;  |----------------
    399 	    return n;   |----------------
    400 	}               |----------------
    401 	                |----------------
    402 	int g = 1;      |----------------
    403 	                |----------------
    404 	int bar(int a) {|int bar(int a) {
    405 	    a *= 2;     |    a *= 2;
    406 	    a += 3;     |    a += 3;
    407 	    return a;   |    return a;
    408 	}               |}
    409 	----------------|
    410 	----------------|int foo() {
    411 	----------------|    int n = 999;
    412 	----------------|    return n;
    413 	----------------|}
    414 	----------------|
    415 	----------------|int g = 1;
    416 <
    417 What we want is to instead ask the diff to align on `foo()`: >
    418 
    419 	----------------|int bar(int a) {
    420 	----------------|    a *= 2;
    421 	----------------|    a += 3;
    422 	----------------|    return a;
    423 	----------------|}
    424 	----------------|
    425 	int foo() {     |int foo() {
    426 	    int n = 1;  |    int n = 999;
    427 	    return n;   |    return n;
    428 	}               |}
    429 	                |
    430 	int g = 1;      |int g = 1;
    431 	                |----------------
    432 	int bar(int a) {|----------------
    433 	    a *= 2;     |----------------
    434 	    a += 3;     |----------------
    435 	    return a;   |----------------
    436 	}               |----------------
    437 <
    438 
    439 Below are some ways of setting diff anchors to get the above result.  In each
    440 example, 'diffopt' needs to have `anchor` set for this to take effect.
    441 
    442 Marks: Set the |'a| mark on the `int foo()` lines in each file first before
    443 setting the anchors: >
    444 	set diffanchors='a
    445 
    446 Pattern: Specify the anchor using a |pattern| (see |:/|).  Here, we make sure
    447 to always start search from line 1 for consistency: >
    448 	set diffanchors=1/int\ foo(/
    449 <
    450 Selection: Use visual mode to select the entire `foo()` function body in each
    451 file.  Here, we use two anchors.  This does a better job of making sure only
    452 the function bodies are anchored against each other but not the lines after
    453 it.  Note the `'>+1` below.  The "+1" is necessary as we want the split to
    454 happen below the last line of the function, not above: >
    455 	set diffanchors='<,'>+1
    456 <
    457 Manually set two anchors using line numbers via buffer-local options: >
    458 	setlocal diffanchors=1,5
    459 	wincmd w
    460 	setlocal diffanchors=7,11
    461 <
    462 ==============================================================================
    463 6. Diff options						*diff-options*
    464 
    465 Also see 'diffopt' and the "diff" item of 'fillchars'.
    466 
    467 					    *diff-slow* *diff_translations*
    468 For very long lines, the diff syntax highlighting might be slow, especially
    469 since it tries to match all different kind of localisations.  To disable
    470 localisations and speed up the syntax highlighting, set the global variable
    471 g:diff_translations to zero: >
    472 
    473     let g:diff_translations = 0
    474 <
    475 After setting this variable, reload the syntax script: >
    476 
    477     set syntax=diff
    478 <
    479 
    480 
    481 FINDING THE DIFFERENCES					*diff-diffexpr*
    482 
    483 The 'diffexpr' option can be set to use something else than the internal diff
    484 support or the standard "diff" program to compare two files and find the
    485 differences. *E959*
    486 
    487 When 'diffexpr' is empty, Vim uses this command to find the differences
    488 between file1 and file2: >
    489 
    490 	diff file1 file2 > outfile
    491 
    492 The ">" is replaced with the value of 'shellredir'.
    493 
    494 The output of "diff" must be a normal "ed" style diff or a unified diff.  A
    495 context diff will NOT work.  For a unified diff no context lines can be used.
    496 Using "diff -u" will NOT work, use "diff -U0".
    497 
    498 This example explains the format that Vim expects for the "ed" style diff: >
    499 
    500 	1a2
    501 	> bbb
    502 	4d4
    503 	< 111
    504 	7c7
    505 	< GGG
    506 	---
    507 	> ggg
    508 
    509 The "1a2" item appends the line "bbb".
    510 The "4d4" item deletes the line "111".
    511 The "7c7" item replaces the line "GGG" with "ggg".
    512 
    513 When 'diffexpr' is not empty, Vim evaluates it to obtain a diff file in the
    514 format mentioned.  These variables are set to the file names used:
    515 
    516 	v:fname_in		original file
    517 	v:fname_new		new version of the same file
    518 	v:fname_out		where to write the resulting diff file
    519 
    520 Additionally, 'diffexpr' should take care of "icase" and "iwhite" in the
    521 'diffopt' option.  'diffexpr' cannot change the value of 'lines' and
    522 'columns'.
    523 
    524 The advantage of using a function call without arguments is that it is faster,
    525 see |expr-option-function|.
    526 
    527 Example (this does almost the same as 'diffexpr' being empty): >
    528 
    529 	set diffexpr=MyDiff()
    530 	function MyDiff()
    531 	   let opt = ""
    532 	   if &diffopt =~ "icase"
    533 	     let opt = opt .. "-i "
    534 	   endif
    535 	   if &diffopt =~ "iwhite"
    536 	     let opt = opt .. "-b "
    537 	   endif
    538 	   silent execute "!diff -a --binary " .. opt .. v:fname_in .. " " .. v:fname_new ..
    539 		\  " > " .. v:fname_out
    540 	   redraw!
    541 	endfunction
    542 
    543 The "-a" argument is used to force comparing the files as text, comparing as
    544 binaries isn't useful.  The "--binary" argument makes the files read in binary
    545 mode, so that a CTRL-Z doesn't end the text on DOS.
    546 
    547 The `redraw!` command may not be needed, depending on whether executing a
    548 shell command shows something on the display or not.
    549 
    550 If the 'diffexpr' expression starts with s: or |<SID>|, then it is replaced
    551 with the script ID (|local-function|).  Example: >
    552 		set diffexpr=s:MyDiffExpr()
    553 		set diffexpr=<SID>SomeDiffExpr()
    554 Otherwise, the expression is evaluated in the context of the script where the
    555 option was set, thus script-local items are available.
    556 
    557 						*E810* *E97*
    558 Vim will do a test if the diff output looks alright.  If it doesn't, you will
    559 get an error message.  Possible causes:
    560 -  The "diff" program cannot be executed.
    561 -  The "diff" program doesn't produce normal "ed" style diffs (see above).
    562 -  The 'shell' and associated options are not set correctly.  Try if filtering
    563    works with a command like ":!sort".
    564 -  You are using 'diffexpr' and it doesn't work.
    565 If it's not clear what the problem is set the 'verbose' option to one or more
    566 to see more messages.
    567 
    568 The self-installing Vim for MS-Windows includes a diff program.  If you don't
    569 have it you might want to download a diff.exe.  For example from
    570 http://gnuwin32.sourceforge.net/packages/diffutils.htm.
    571 
    572 
    573 USING PATCHES					*diff-patchexpr*
    574 
    575 The 'patchexpr' option can be set to use something else than the standard
    576 "patch" program.
    577 
    578 When 'patchexpr' is empty, Vim will call the "patch" program like this: >
    579 
    580 	patch -o outfile origfile < patchfile
    581 
    582 This should work fine with most versions of the "patch" program.  Note that a
    583 CR in the middle of a line may cause problems, it is seen as a line break.
    584 
    585 If the default doesn't work for you, set the 'patchexpr' to an expression that
    586 will have the same effect.  These variables are set to the file names used:
    587 
    588 	v:fname_in		original file
    589 	v:fname_diff		patch file
    590 	v:fname_out		resulting patched file
    591 
    592 The advantage of using a function call without arguments is that it is faster,
    593 see |expr-option-function|.
    594 
    595 Example (this does the same as 'patchexpr' being empty): >
    596 
    597 	set patchexpr=MyPatch()
    598 	function MyPatch()
    599 	   :call system("patch -o " .. v:fname_out .. " " .. v:fname_in ..
    600 	   \  " < " .. v:fname_diff)
    601 	endfunction
    602 
    603 Make sure that using the "patch" program doesn't have unwanted side effects.
    604 For example, watch out for additionally generated files, which should be
    605 deleted.  It should just patch the file and nothing else.
    606    Vim will change directory to "/tmp" or another temp directory before
    607 evaluating 'patchexpr'.  This hopefully avoids that files in the current
    608 directory are accidentally patched.  Vim will also delete files starting with
    609 v:fname_in and ending in ".rej" and ".orig".
    610 
    611 If the 'patchexpr' expression starts with s: or |<SID>|, then it is replaced
    612 with the script ID (|local-function|).  Example: >
    613 		set patchexpr=s:MyPatchExpr()
    614 		set patchexpr=<SID>SomePatchExpr()
    615 Otherwise, the expression is evaluated in the context of the script where the
    616 option was set, thus script-local items are available.
    617 
    618 
    619 DIFF FUNCTION EXAMPLES				*diff-func-examples*
    620 
    621 Some examples for using the |diff()| function to compute the diff indices
    622 between two Lists of strings are below.
    623 >
    624   " some lines are changed
    625   :echo diff(['abc', 'def', 'ghi'], ['abx', 'rrr', 'xhi'], {'output': 'indices'})
    626    [{'from_idx': 0, 'from_count': 3, 'to_idx': 0, 'to_count': 3}]
    627 
    628   " few lines added at the beginning
    629   :echo diff(['ghi'], ['abc', 'def', 'ghi'], {'output': 'indices'})
    630    [{'from_idx': 0, 'from_count': 0, 'to_idx': 0, 'to_count': 2}]
    631 
    632   " few lines removed from the beginning
    633   :echo diff(['abc', 'def', 'ghi'], ['ghi'], {'output': 'indices'})
    634    [{'from_idx': 0, 'from_count': 2, 'to_idx': 0, 'to_count': 0}]
    635 
    636   " few lines added in the middle
    637   :echo diff(['abc', 'jkl'], ['abc', 'def', 'ghi', 'jkl'], {'output': 'indices'})
    638    [{'from_idx': 1, 'from_count': 0, 'to_idx': 1, 'to_count': 2}]
    639 
    640   " few lines removed in the middle
    641   :echo diff(['abc', 'def', 'ghi', 'jkl'], ['abc', 'jkl'], {'output': 'indices'})
    642    [{'from_idx': 1, 'from_count': 2, 'to_idx': 1, 'to_count': 0}]
    643 
    644   " few lines added at the end
    645   :echo diff(['abc'], ['abc', 'def', 'ghi'], {'output': 'indices'})
    646    [{'from_idx': 1, 'from_count': 0, 'to_idx': 1, 'to_count': 2}]
    647 
    648   " few lines removed from the end
    649   :echo diff(['abc', 'def', 'ghi'], ['abc'], {'output': 'indices'})
    650    [{'from_idx': 1, 'from_count': 2, 'to_idx': 1, 'to_count': 0}]
    651 
    652   " disjointed changes
    653   :echo diff(['ab', 'def', 'ghi', 'jkl'], ['abc', 'def', 'ghi', 'jk'], {'output': 'indices', 'context': 0})
    654    [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1},
    655     {'from_idx': 3, 'from_count': 1, 'to_idx': 3, 'to_count': 1}]
    656 
    657   " disjointed changes with context length 1
    658   :echo diff(['ab', 'def', 'ghi', 'jkl'], ['abc', 'def', 'ghi', 'jk'], {'output': 'indices', 'context': 1})
    659    [{'from_idx': 0, 'from_count': 4, 'to_idx': 0, 'to_count': 4}]
    660 
    661 <
    662 
    663  vim:tw=78:ts=8:noet:ft=help:norl: