comparison 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
comparison
equal deleted inserted replaced
23603:483d395694b0 23604:1816ea68c022
312 similar to -1. > 312 similar to -1. >
313 :let endlist = mylist[2:] " from item 2 to the end: [3, "four"] 313 :let endlist = mylist[2:] " from item 2 to the end: [3, "four"]
314 :let shortlist = mylist[2:2] " List with one item: [3] 314 :let shortlist = mylist[2:2] " List with one item: [3]
315 :let otherlist = mylist[:] " make a copy of the List 315 :let otherlist = mylist[:] " make a copy of the List
316 316
317 Notice that the last index is inclusive. If you prefer using an exclusive
318 index use the |slice()| method.
319
317 If the first index is beyond the last item of the List or the second item is 320 If the first index is beyond the last item of the List or the second item is
318 before the first item, the result is an empty list. There is no error 321 before the first item, the result is an empty list. There is no error
319 message. 322 message.
320 323
321 If the second index is equal to or greater than the length of the list the 324 If the second index is equal to or greater than the length of the list the
1214 multibyte encodings, see |byteidx()| for computing the indexes. If expr8 is 1217 multibyte encodings, see |byteidx()| for computing the indexes. If expr8 is
1215 a Number it is first converted to a String. 1218 a Number it is first converted to a String.
1216 1219
1217 In Vim9 script the indexes are character indexes. To use byte indexes use 1220 In Vim9 script the indexes are character indexes. To use byte indexes use
1218 |strpart()|. 1221 |strpart()|.
1222
1223 The item at index expr1b is included, it is inclusive. For an exclusive index
1224 use the |slice()| function.
1219 1225
1220 If expr1a is omitted zero is used. If expr1b is omitted the length of the 1226 If expr1a is omitted zero is used. If expr1b is omitted the length of the
1221 string minus one is used. 1227 string minus one is used.
1222 1228
1223 A negative number can be used to measure from the end of the string. -1 is 1229 A negative number can be used to measure from the end of the string. -1 is
2882 Number unplace a sign 2888 Number unplace a sign
2883 sign_unplacelist({list}) List unplace a list of signs 2889 sign_unplacelist({list}) List unplace a list of signs
2884 simplify({filename}) String simplify filename as much as possible 2890 simplify({filename}) String simplify filename as much as possible
2885 sin({expr}) Float sine of {expr} 2891 sin({expr}) Float sine of {expr}
2886 sinh({expr}) Float hyperbolic sine of {expr} 2892 sinh({expr}) Float hyperbolic sine of {expr}
2893 slice({expr}, {start} [, {end}]) String, List or Blob
2894 slice of a String, List or Blob
2887 sort({list} [, {func} [, {dict}]]) 2895 sort({list} [, {func} [, {dict}]])
2888 List sort {list}, using {func} to compare 2896 List sort {list}, using {func} to compare
2889 sound_clear() none stop playing all sounds 2897 sound_clear() none stop playing all sounds
2890 sound_playevent({name} [, {callback}]) 2898 sound_playevent({name} [, {callback}])
2891 Number play an event sound 2899 Number play an event sound
9858 9866
9859 Can also be used as a |method|: > 9867 Can also be used as a |method|: >
9860 Compute()->sinh() 9868 Compute()->sinh()
9861 < 9869 <
9862 {only available when compiled with the |+float| feature} 9870 {only available when compiled with the |+float| feature}
9871
9872
9873 slice({expr}, {start} [, {end}]) *slice()*
9874 Similar to using a |slice| "expr[start : end]", but "end" is
9875 used exclusive. And for a string the indexes are used as
9876 character indexes instead of byte indexes, like in
9877 |vim9script|.
9878 When {end} is omitted the slice continues to the last item.
9879 When {end} is -1 the last item is omitted.
9880
9881 Can also be used as a |method|: >
9882 GetList()->slice(offset)
9863 9883
9864 9884
9865 sort({list} [, {func} [, {dict}]]) *sort()* *E702* 9885 sort({list} [, {func} [, {dict}]]) *sort()* *E702*
9866 Sort the items in {list} in-place. Returns {list}. 9886 Sort the items in {list} in-place. Returns {list}.
9867 9887