aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-05-04 16:46:38 +0800
committerzeertzjq <zeertzjq@outlook.com>2023-05-04 17:40:29 +0800
commitb441dafdf53e367c7d43177274bd781c5c73e6e0 (patch)
tree4c8838192ce80a1ed652dd5bbda3c265678cdbea /runtime
parent62351ff3d2fba336f09569d844a7b6f7f36a078d (diff)
downloadrneovim-b441dafdf53e367c7d43177274bd781c5c73e6e0.tar.gz
rneovim-b441dafdf53e367c7d43177274bd781c5c73e6e0.tar.bz2
rneovim-b441dafdf53e367c7d43177274bd781c5c73e6e0.zip
vim-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 vim/vim#7408) https://github.com/vim/vim/commit/6601b62943a19d4f8818c3638440663d67a17b6a Cherry-pick a line in docs added later. Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/builtin.txt14
-rw-r--r--runtime/doc/eval.txt6
-rw-r--r--runtime/doc/usr_41.txt3
3 files changed, 23 insertions, 0 deletions
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index b37ac117f3..5be9ba910b 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -464,6 +464,8 @@ sign_unplacelist({list}) List unplace a list of signs
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
sockconnect({mode}, {address} [, {opts}])
Number Connects to socket
sort({list} [, {func} [, {dict}]])
@@ -7773,6 +7775,18 @@ sinh({expr}) *sinh()*
Can also be used as a |method|: >
Compute()->sinh()
+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.
+ When {end} is omitted the slice continues to the last item.
+ When {end} is -1 the last item is omitted.
+ Returns an empty value if {start} or {end} are invalid.
+
+ Can also be used as a |method|: >
+ GetList()->slice(offset)
+
+
sockconnect({mode}, {address} [, {opts}]) *sockconnect()*
Connect a socket to an address. If {mode} is "pipe" then
{address} should be the path of a local domain socket (on
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 9ee38e06d6..05fdf2f5bb 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -270,6 +270,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.
@@ -1178,6 +1181,9 @@ In legacy Vim script the indexes are byte indexes. This doesn't recognize
multibyte encodings, see |byteidx()| for computing the indexes. If expr8 is
a Number it is first converted to a String.
+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.
diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt
index 8e1b72eadc..9075d60b1b 100644
--- a/runtime/doc/usr_41.txt
+++ b/runtime/doc/usr_41.txt
@@ -630,6 +630,8 @@ String manipulation: *string-functions*
submatch() get a specific match in ":s" and substitute()
strpart() get part of a string using byte index
strcharpart() get part of a string using char index
+ slice() take a slice of a string, using char index in
+ Vim9 script
strgetchar() get character from a string using char index
expand() expand special keywords
expandcmd() expand a command like done for `:edit`
@@ -659,6 +661,7 @@ List manipulation: *list-functions*
filter() remove selected items from a List
map() change each List item
reduce() reduce a List to a value
+ slice() take a slice of a List
sort() sort a List
reverse() reverse the order of a List or Blob
uniq() remove copies of repeated adjacent items