comparison runtime/doc/diff.txt @ 34264:cce6b834635c v9.1.0071

patch 9.1.0071: Need a diff() Vim script function Commit: https://github.com/vim/vim/commit/fa37835b8c0ed0f83952978fca4c332335ca7c46 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Thu Feb 1 22:05:27 2024 +0100 patch 9.1.0071: Need a diff() Vim script function Problem: Need a diff() Vim script function Solution: Add the diff() Vim script function using the xdiff internal diff library, add support for "unified" and "indices" mode. (Yegappan Lakshmanan) fixes: #4241 closes: #12321 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 01 Feb 2024 22:30:03 +0100
parents 4635e43f2c6f
children 7ccaadd7cf0b
comparison
equal deleted inserted replaced
34263:547c4b60760a 34264:cce6b834635c
1 *diff.txt* For Vim version 9.1. Last change: 2023 Apr 04 1 *diff.txt* For Vim version 9.1. Last change: 2024 Feb 01
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
474 set patchexpr=<SID>SomePatchExpr() 474 set patchexpr=<SID>SomePatchExpr()
475 Otherwise, the expression is evaluated in the context of the script where the 475 Otherwise, the expression is evaluated in the context of the script where the
476 option was set, thus script-local items are available. 476 option was set, thus script-local items are available.
477 477
478 478
479 DIFF FUNCTION EXAMPLES *diff-func-examples*
480
481 Some examples for using the |diff()| function to compute the diff indices
482 between two Lists of strings are below.
483 >
484 " some lines are changed
485 :echo diff(['abc', 'def', 'ghi'], ['abx', 'rrr', 'xhi'], {'output': 'indices'})
486 [{'from_idx': 0, 'from_count': 3, 'to_idx': 0, 'to_count': 3}]
487
488 " few lines added at the beginning
489 :echo diff(['ghi'], ['abc', 'def', 'ghi'], {'output': 'indices'})
490 [{'from_idx': 0, 'from_count': 0, 'to_idx': 0, 'to_count': 2}]
491
492 " few lines removed from the beginning
493 :echo diff(['abc', 'def', 'ghi'], ['ghi'], {'output': 'indices'})
494 [{'from_idx': 0, 'from_count': 2, 'to_idx': 0, 'to_count': 0}]
495
496 " few lines added in the middle
497 :echo diff(['abc', 'jkl'], ['abc', 'def', 'ghi', 'jkl'], {'output': 'indices'})
498 [{'from_idx': 1, 'from_count': 0, 'to_idx': 1, 'to_count': 2}]
499
500 " few lines removed in the middle
501 :echo diff(['abc', 'def', 'ghi', 'jkl'], ['abc', 'jkl'], {'output': 'indices'})
502 [{'from_idx': 1, 'from_count': 2, 'to_idx': 1, 'to_count': 0}]
503
504 " few lines added at the end
505 :echo diff(['abc'], ['abc', 'def', 'ghi'], {'output': 'indices'})
506 [{'from_idx': 1, 'from_count': 0, 'to_idx': 1, 'to_count': 2}]
507
508 " few lines removed from the end
509 :echo diff(['abc', 'def', 'ghi'], ['abc'], {'output': 'indices'})
510 [{'from_idx': 1, 'from_count': 2, 'to_idx': 1, 'to_count': 0}]
511
512 " disjointed changes
513 :echo diff(['ab', 'def', 'ghi', 'jkl'], ['abc', 'def', 'ghi', 'jk'], {'output': 'indices'})
514 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1},
515 {'from_idx': 3, 'from_count': 1, 'to_idx': 3, 'to_count': 1}]
516 <
517
479 vim:tw=78:ts=8:noet:ft=help:norl: 518 vim:tw=78:ts=8:noet:ft=help:norl: