comparison runtime/doc/builtin.txt @ 29712:bdb31515f78b v9.0.0196

patch 9.0.0196: finding value in list may require a for loop Commit: https://github.com/vim/vim/commit/b218655d5a485f5b193fb18d7240837d42b89812 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sat Aug 13 13:09:20 2022 +0100 patch 9.0.0196: finding value in list may require a for loop Problem: Finding value in list may require a for loop. Solution: Add indexof(). (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/10903)
author Bram Moolenaar <Bram@vim.org>
date Sat, 13 Aug 2022 14:15:05 +0200
parents 9b8ab82e3b0b
children 66f9877b8aab
comparison
equal deleted inserted replaced
29711:4069513e8995 29712:bdb31515f78b
289 hostname() String name of the machine Vim is running on 289 hostname() String name of the machine Vim is running on
290 iconv({expr}, {from}, {to}) String convert encoding of {expr} 290 iconv({expr}, {from}, {to}) String convert encoding of {expr}
291 indent({lnum}) Number indent of line {lnum} 291 indent({lnum}) Number indent of line {lnum}
292 index({object}, {expr} [, {start} [, {ic}]]) 292 index({object}, {expr} [, {start} [, {ic}]])
293 Number index in {object} where {expr} appears 293 Number index in {object} where {expr} appears
294 indexof({object}, {expr} [, {opts}]])
295 Number index in {object} where {expr} is true
294 input({prompt} [, {text} [, {completion}]]) 296 input({prompt} [, {text} [, {completion}]])
295 String get input from the user 297 String get input from the user
296 inputdialog({prompt} [, {text} [, {cancelreturn}]]) 298 inputdialog({prompt} [, {text} [, {cancelreturn}]])
297 String like input() but in a GUI dialog 299 String like input() but in a GUI dialog
298 inputlist({textlist}) Number let the user pick from a choice list 300 inputlist({textlist}) Number let the user pick from a choice list
4728 4730
4729 Can also be used as a |method|: > 4731 Can also be used as a |method|: >
4730 GetLnum()->indent() 4732 GetLnum()->indent()
4731 4733
4732 index({object}, {expr} [, {start} [, {ic}]]) *index()* 4734 index({object}, {expr} [, {start} [, {ic}]]) *index()*
4735 Find {expr} in {object} and return its index. See
4736 |filterof()| for using a lambda to select the item.
4737
4733 If {object} is a |List| return the lowest index where the item 4738 If {object} is a |List| return the lowest index where the item
4734 has a value equal to {expr}. There is no automatic 4739 has a value equal to {expr}. There is no automatic
4735 conversion, so the String "4" is different from the Number 4. 4740 conversion, so the String "4" is different from the Number 4.
4736 And the number 4 is different from the Float 4.0. The value 4741 And the number 4 is different from the Float 4.0. The value
4737 of 'ignorecase' is not used here, case always matters. 4742 of 'ignorecase' is not used here, case matters as indicated by
4743 the {ic} argument.
4738 4744
4739 If {object} is |Blob| return the lowest index where the byte 4745 If {object} is |Blob| return the lowest index where the byte
4740 value is equal to {expr}. 4746 value is equal to {expr}.
4741 4747
4742 If {start} is given then start looking at the item with index 4748 If {start} is given then start looking at the item with index
4743 {start} (may be negative for an item relative to the end). 4749 {start} (may be negative for an item relative to the end).
4750
4744 When {ic} is given and it is |TRUE|, ignore case. Otherwise 4751 When {ic} is given and it is |TRUE|, ignore case. Otherwise
4745 case must match. 4752 case must match.
4753
4746 -1 is returned when {expr} is not found in {object}. 4754 -1 is returned when {expr} is not found in {object}.
4747 Example: > 4755 Example: >
4748 :let idx = index(words, "the") 4756 :let idx = index(words, "the")
4749 :if index(numbers, 123) >= 0 4757 :if index(numbers, 123) >= 0
4750 4758
4751 < Can also be used as a |method|: > 4759 < Can also be used as a |method|: >
4752 GetObject()->index(what) 4760 GetObject()->index(what)
4761
4762 indexof({object}, {expr} [, {opt}]) *indexof()*
4763 {object} must be a |List| or a |Blob|.
4764 If {object} is a |List|, evaluate {expr} for each item in the
4765 List until the expression returns v:true and return the index
4766 of this item.
4767
4768 If {object} is a |Blob| evaluate {expr} for each byte in the
4769 Blob until the expression returns v:true and return the index
4770 of this byte.
4771
4772 {expr} must be a |string| or |Funcref|.
4773
4774 If {expr} is a |string|: If {object} is a |List|, inside
4775 {expr} |v:key| has the index of the current List item and
4776 |v:val| has the value of the item. If {object} is a |Blob|,
4777 inside {expr} |v:key| has the index of the current byte and
4778 |v:val| has the byte value.
4779
4780 If {expr} is a |Funcref| it must take two arguments:
4781 1. the key or the index of the current item.
4782 2. the value of the current item.
4783 The function must return |TRUE| if the item is found and the
4784 search should stop.
4785
4786 The optional argument {opt} is a Dict and supports the
4787 following items:
4788 start start evaluating {expr} at the item with index
4789 {start} (may be negative for an item relative
4790 to the end).
4791 Returns -1 when {expr} evaluates to v:false for all the items.
4792 Example: >
4793 :let l = [#{n: 10}, #{n: 20}, #{n: 30]]
4794 :let idx = indexof(l, "v:val.n == 20")
4795 :let idx = indexof(l, {i, v -> v.n == 30})
4796
4797 < Can also be used as a |method|: >
4798 mylist->indexof(expr)
4753 4799
4754 input({prompt} [, {text} [, {completion}]]) *input()* 4800 input({prompt} [, {text} [, {completion}]]) *input()*
4755 The result is a String, which is whatever the user typed on 4801 The result is a String, which is whatever the user typed on
4756 the command-line. The {prompt} argument is either a prompt 4802 the command-line. The {prompt} argument is either a prompt
4757 string, or a blank string (for no prompt). A '\n' can be used 4803 string, or a blank string (for no prompt). A '\n' can be used