|
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 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar
|
@@ -476,4 +476,48 @@ Otherwise, the expression is evaluated in the context of the script where the
|
476 | 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', 'context': 0}) |
| 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 | + " disjointed changes with context length 1 |
| 518 | + :echo diff(['ab', 'def', 'ghi', 'jkl'], ['abc', 'def', 'ghi', 'jk'], {'output': 'indices', 'context': 1}) |
| 519 | + [{'from_idx': 0, 'from_count': 4, 'to_idx': 0, 'to_count': 4}] |
| 520 | +
|
| 521 | +< |
| 522 | + |
479 | 523 | vim:tw=78:ts=8:noet:ft=help:norl:
|
0 commit comments