diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2022-08-13 21:35:13 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-08-13 21:35:13 +0100 |
commit | 3fbf6cd355de2212e9227f57d545592aae3f688f (patch) | |
tree | 659f4b00bea60f1935a683a5b6a51ab19912d3d4 /runtime | |
parent | 9113c2cd19c72c0973ee5dc095a0a7f03f2af344 (diff) | |
download | vim-git-3fbf6cd355de2212e9227f57d545592aae3f688f.tar.gz |
patch 9.0.0202: code and help for indexof() is not idealv9.0.0202
Problem: Code and help for indexof() is not ideal.
Solution: Refactor the code, improve the help. (Yegappan Lakshmanan,
closes #10908)
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/builtin.txt | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index 3c0f143c5..cc4e7c4a8 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -4733,7 +4733,7 @@ indent({lnum}) The result is a Number, which is indent of line {lnum} in the index({object}, {expr} [, {start} [, {ic}]]) *index()* Find {expr} in {object} and return its index. See - |filterof()| for using a lambda to select the item. + |indexof()| for using a lambda to select the item. If {object} is a |List| return the lowest index where the item has a value equal to {expr}. There is no automatic @@ -4759,15 +4759,17 @@ index({object}, {expr} [, {start} [, {ic}]]) *index()* < Can also be used as a |method|: > GetObject()->index(what) -indexof({object}, {expr} [, {opt}]) *indexof()* - {object} must be a |List| or a |Blob|. +indexof({object}, {expr} [, {opts}]) *indexof()* + Returns the index of an item in {object} where {expr} is + v:true. {object} must be a |List| or a |Blob|. + If {object} is a |List|, evaluate {expr} for each item in the - List until the expression returns v:true and return the index - of this item. + List until the expression is v:true and return the index of + this item. If {object} is a |Blob| evaluate {expr} for each byte in the - Blob until the expression returns v:true and return the index - of this byte. + Blob until the expression is v:true and return the index of + this byte. {expr} must be a |string| or |Funcref|. @@ -4783,16 +4785,17 @@ indexof({object}, {expr} [, {opt}]) *indexof()* The function must return |TRUE| if the item is found and the search should stop. - The optional argument {opt} is a Dict and supports the + The optional argument {opts} is a Dict and supports the following items: - start start evaluating {expr} at the item with index - {start} (may be negative for an item relative - to the end). + startidx start evaluating {expr} at the item with this + index; may be negative for an item relative to + the end Returns -1 when {expr} evaluates to v:false for all the items. Example: > - :let l = [#{n: 10}, #{n: 20}, #{n: 30]] - :let idx = indexof(l, "v:val.n == 20") - :let idx = indexof(l, {i, v -> v.n == 30}) + :let l = [#{n: 10}, #{n: 20}, #{n: 30}] + :echo indexof(l, "v:val.n == 20") + :echo indexof(l, {i, v -> v.n == 30}) + :echo indexof(l, "v:val.n == 20", #{startidx: 1}) < Can also be used as a |method|: > mylist->indexof(expr) |