summaryrefslogtreecommitdiffstats
path: root/runtime/doc/diff.txt
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2024-02-01 22:05:27 +0100
committerChristian Brabandt <cb@256bit.org>2024-02-01 22:05:27 +0100
commitfa37835b8c0ed0f83952978fca4c332335ca7c46 (patch)
treea10eb5ac624dfc8c160581fe4b033b1e5b0e27d6 /runtime/doc/diff.txt
parent1226b0584a07417882ea48763977f3ae24430e0e (diff)
patch 9.1.0071: Need a diff() Vim script functionv9.1.0071
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>
Diffstat (limited to 'runtime/doc/diff.txt')
-rw-r--r--runtime/doc/diff.txt41
1 files changed, 40 insertions, 1 deletions
diff --git a/runtime/doc/diff.txt b/runtime/doc/diff.txt
index 91b004745a..05dd4a6be9 100644
--- a/runtime/doc/diff.txt
+++ b/runtime/doc/diff.txt
@@ -1,4 +1,4 @@
-*diff.txt* For Vim version 9.1. Last change: 2023 Apr 04
+*diff.txt* For Vim version 9.1. Last change: 2024 Feb 01
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -476,4 +476,43 @@ Otherwise, the expression is evaluated in the context of the script where the
option was set, thus script-local items are available.
+DIFF FUNCTION EXAMPLES *diff-func-examples*
+
+Some examples for using the |diff()| function to compute the diff indices
+between two Lists of strings are below.
+>
+ " some lines are changed
+ :echo diff(['abc', 'def', 'ghi'], ['abx', 'rrr', 'xhi'], {'output': 'indices'})
+ [{'from_idx': 0, 'from_count': 3, 'to_idx': 0, 'to_count': 3}]
+
+ " few lines added at the beginning
+ :echo diff(['ghi'], ['abc', 'def', 'ghi'], {'output': 'indices'})
+ [{'from_idx': 0, 'from_count': 0, 'to_idx': 0, 'to_count': 2}]
+
+ " few lines removed from the beginning
+ :echo diff(['abc', 'def', 'ghi'], ['ghi'], {'output': 'indices'})
+ [{'from_idx': 0, 'from_count': 2, 'to_idx': 0, 'to_count': 0}]
+
+ " few lines added in the middle
+ :echo diff(['abc', 'jkl'], ['abc', 'def', 'ghi', 'jkl'], {'output': 'indices'})
+ [{'from_idx': 1, 'from_count': 0, 'to_idx': 1, 'to_count': 2}]
+
+ " few lines removed in the middle
+ :echo diff(['abc', 'def', 'ghi', 'jkl'], ['abc', 'jkl'], {'output': 'indices'})
+ [{'from_idx': 1, 'from_count': 2, 'to_idx': 1, 'to_count': 0}]
+
+ " few lines added at the end
+ :echo diff(['abc'], ['abc', 'def', 'ghi'], {'output': 'indices'})
+ [{'from_idx': 1, 'from_count': 0, 'to_idx': 1, 'to_count': 2}]
+
+ " few lines removed from the end
+ :echo diff(['abc', 'def', 'ghi'], ['abc'], {'output': 'indices'})
+ [{'from_idx': 1, 'from_count': 2, 'to_idx': 1, 'to_count': 0}]
+
+ " disjointed changes
+ :echo diff(['ab', 'def', 'ghi', 'jkl'], ['abc', 'def', 'ghi', 'jk'], {'output': 'indices'})
+ [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1},
+ {'from_idx': 3, 'from_count': 1, 'to_idx': 3, 'to_count': 1}]
+<
+
vim:tw=78:ts=8:noet:ft=help:norl: