Home Explore Blog CI



neovim

62th chunk of `runtime/doc/vimfn.txt`
840531033950a28b998ff8cd7d371593f77856962720170f0000000100000fba
	the {ic} argument.

		If {object} is a |Blob| return the lowest index where the byte
		value is equal to {expr}.

		If {start} is given then start looking at the item with index
		{start} (may be negative for an item relative to the end).

		When {ic} is given and it is |TRUE|, ignore case.  Otherwise
		case must match.

		-1 is returned when {expr} is not found in {object}.
		Example: >vim
			let idx = index(words, "the")
			if index(numbers, 123) >= 0
			  " ...
			endif
<

                Parameters: ~
                  • {object} (`any`)
                  • {expr} (`any`)
                  • {start} (`integer?`)
                  • {ic} (`boolean?`)

                Return: ~
                  (`integer`)

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 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 is v:true and return the index of
		this byte.

		{expr} must be a |string| or |Funcref|.

		If {expr} is a |string|: If {object} is a |List|, inside
		{expr} |v:key| has the index of the current List item and
		|v:val| has the value of the item.  If {object} is a |Blob|,
		inside {expr} |v:key| has the index of the current byte and
		|v:val| has the byte value.

		If {expr} is a |Funcref| it must take two arguments:
			1. the key or the index of the current item.
			2. the value of the current item.
		The function must return |TRUE| if the item is found and the
		search should stop.

		The optional argument {opts} is a Dict and supports the
		following items:
		    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: >vim
			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})
<

                Parameters: ~
                  • {object} (`any`)
                  • {expr} (`any`)
                  • {opts} (`table?`)

                Return: ~
                  (`integer`)

input({prompt} [, {text} [, {completion}]])                            *input()*

                Parameters: ~
                  • {prompt} (`string`)
                  • {text} (`string?`)
                  • {completion} (`string?`)

                Return: ~
                  (`string`)

input({opts})
		The result is a String, which is whatever the user typed on
		the command-line.  The {prompt} argument is either a prompt
		string, or a blank string (for no prompt).  A '\n' can be used
		in the prompt to start a new line.

		In the second form it accepts a single dictionary with the
		following keys, any of which may be omitted:

		Key           Default  Description ~
		prompt        ""       Same as {prompt} in the first form.
		default       ""       Same as {text} in the first form.
		completion    nothing  Same as {completion} in the first form.
		cancelreturn  ""       The value returned when the dialog is
		                       cancelled.
		highlight     nothing  Highlight handler: |Funcref|.

		The highlighting set with |:echohl| is used for the prompt.
		The input is entered just like a command-line, with the same
		editing commands and mappings.  There is a separate history
		for lines typed for input().
		Example: >vim
			if input("Coffee or beer? ") == "beer"
			  echo "Cheers!"
			endif
<
		If the optional {text} argument is present and not empty, this
		is used for the default reply, as if the user typed this.
		Example: >vim
			let color = input("Color? ", "white")

<		The optional {completion} argument specifies the type of
		completion supported for the input.  Without

Title: Documentation for `index()` and `indexof()` Functions (Continued), and `input()`
Summary
This section continues the documentation for the `index()` and `indexof()` functions, providing details on optional arguments and behavior with Lists and Blobs. It then introduces the `input()` function, which prompts the user for input on the command-line and returns the entered string. The function can accept a prompt string, a default text, and a completion type, and also includes optional arguments for cancel return values and highlight handlers.