Home Explore Blog CI



neovim

34th chunk of `runtime/doc/vimfn.txt`
03416057f245782a4fd35ce4d12649cfb8f4602da6df8d0b0000000100000faf
 current item.  For a |Blob| |v:key| has the index of the
		current byte. For a |String| |v:key| has the index of the
		current character.
		Examples: >vim
			call foreach(mylist, 'let used[v:val] = v:true')
<		This records the items that are in the {expr1} list.

		Note that {expr2} is the result of expression and is then used
		as a command.  Often it is good to use a |literal-string| to
		avoid having to double backslashes.

		If {expr2} 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.
		With a lambda you don't get an error if it only accepts one
		argument.
		If the function returns a value, it is ignored.

		Returns {expr1} in all cases.
		When an error is encountered while executing {expr2} no
		further items in {expr1} are processed.
		When {expr2} is a Funcref errors inside a function are ignored,
		unless it was defined with the "abort" flag.

                Parameters: ~
                  • {expr1} (`string|table`)
                  • {expr2} (`string|function`)

                Return: ~
                  (`string|table`)

fullcommand({name})                                              *fullcommand()*
		Get the full command name from a short abbreviated command
		name; see |20.2| for details on command abbreviations.

		The string argument {name} may start with a `:` and can
		include a [range], these are skipped and not returned.
		Returns an empty string if a command doesn't exist or if it's
		ambiguous (for user-defined commands).

		For example `fullcommand('s')`, `fullcommand('sub')`,
		`fullcommand(':%substitute')` all return "substitute".

                Parameters: ~
                  • {name} (`string`)

                Return: ~
                  (`string`)

funcref({name} [, {arglist}] [, {dict}])                             *funcref()*
		Just like |function()|, but the returned Funcref will lookup
		the function by reference, not by name.  This matters when the
		function {name} is redefined later.

		Unlike |function()|, {name} must be an existing user function.
		It only works for an autoloaded function if it has already
		been loaded (to avoid mistakenly loading the autoload script
		when only intending to use the function name, use |function()|
		instead). {name} cannot be a builtin function.
		Returns 0 on error.

                Parameters: ~
                  • {name} (`string`)
                  • {arglist} (`any?`)
                  • {dict} (`any?`)

                Return: ~
                  (`any`)

function({name} [, {arglist}] [, {dict}])         *function()* *partial* *E700* *E923*
		Return a |Funcref| variable that refers to function {name}.
		{name} can be the name of a user defined function or an
		internal function.

		{name} can also be a Funcref or a partial. When it is a
		partial the dict stored in it will be used and the {dict}
		argument is not allowed. E.g.: >vim
			let FuncWithArg = function(dict.Func, [arg])
			let Broken = function(dict.Func, [arg], dict)
<
		When using the Funcref the function will be found by {name},
		also when it was redefined later. Use |funcref()| to keep the
		same function.

		When {arglist} or {dict} is present this creates a partial.
		That means the argument list and/or the dictionary is stored in
		the Funcref and will be used when the Funcref is called.

		The arguments are passed to the function in front of other
		arguments, but after any argument from |method|.  Example: >vim
			func Callback(arg1, arg2, name)
			"...
			endfunc
			let Partial = function('Callback', ['one', 'two'])
			"...
			call Partial('name')
<		Invokes the function as with: >vim
			call Callback('one', 'two', 'name')

<		With a |method|: >vim
			func Callback(one, two, three)
			"...
			endfunc
			let Partial = function('Callback', ['two'])
			"...
			eval 'one'->Partial('three')
<		Invokes the function as with: >vim
			call Callback('one', 'two', 'three')

<		The function() call can be nested

Title: Vimscript Functions: `fullcommand()`, `funcref()`, and `function()`
Summary
This section describes the functions `fullcommand()`, `funcref()`, and `function()`. `fullcommand()` retrieves the full command name from an abbreviated command. `funcref()` returns a Funcref that looks up a function by reference. `function()` returns a Funcref to a function by name, and can create partial functions when used with {arglist} or {dict} to store arguments.