diff runtime/doc/eval.txt @ 23604:1816ea68c022 v8.2.2344

patch 8.2.2344: using inclusive index for slice is not always desired Commit: https://github.com/vim/vim/commit/6601b62943a19d4f8818c3638440663d67a17b6a Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 13 21:47:15 2021 +0100 patch 8.2.2344: using inclusive index for slice is not always desired Problem: Using inclusive index for slice is not always desired. Solution: Add the slice() method, which has an exclusive index. (closes #7408)
author Bram Moolenaar <Bram@vim.org>
date Wed, 13 Jan 2021 22:00:04 +0100
parents 7b3317e959e3
children 96206643bd9f
line wrap: on
line diff
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -314,6 +314,9 @@ similar to -1. >
 	:let shortlist = mylist[2:2]	" List with one item: [3]
 	:let otherlist = mylist[:]	" make a copy of the List
 
+Notice that the last index is inclusive.  If you prefer using an exclusive
+index use the |slice()| method.
+
 If the first index is beyond the last item of the List or the second item is
 before the first item, the result is an empty list.  There is no error
 message.
@@ -1217,6 +1220,9 @@ a Number it is first converted to a Stri
 In Vim9 script the indexes are character indexes.  To use byte indexes use
 |strpart()|.
 
+The item at index expr1b is included, it is inclusive.  For an exclusive index
+use the |slice()| function.
+
 If expr1a is omitted zero is used.  If expr1b is omitted the length of the
 string minus one is used.
 
@@ -2884,6 +2890,8 @@ sign_unplacelist({list})	List	unplace a 
 simplify({filename})		String	simplify filename as much as possible
 sin({expr})			Float	sine of {expr}
 sinh({expr})			Float	hyperbolic sine of {expr}
+slice({expr}, {start} [, {end}])  String, List or Blob
+					slice of a String, List or Blob
 sort({list} [, {func} [, {dict}]])
 				List	sort {list}, using {func} to compare
 sound_clear()			none	stop playing all sounds
@@ -9862,6 +9870,18 @@ sinh({expr})						*sinh()*
 		{only available when compiled with the |+float| feature}
 
 
+slice({expr}, {start} [, {end}])			*slice()* 
+		Similar to using a |slice| "expr[start : end]", but "end" is
+		used exclusive.  And for a string the indexes are used as
+		character indexes instead of byte indexes, like in
+		|vim9script|.
+		When {end} is omitted the slice continues to the last item.
+		When {end} is -1 the last item is omitted.
+
+		Can also be used as a |method|: >
+			GetList()->slice(offset)
+
+
 sort({list} [, {func} [, {dict}]])			*sort()* *E702*
 		Sort the items in {list} in-place.  Returns {list}.