Home Explore Blog CI



neovim

33th chunk of `runtime/doc/vimfn.txt`
e208949a35ea2e9aa4037b227e80223373691418563a3d210000000100000faa
 with |getline()|.  Thus "." is the current
		line, "'m" mark m, etc.

                Parameters: ~
                  • {lnum} (`integer|string`)

                Return: ~
                  (`integer`)

foldlevel({lnum})                                                  *foldlevel()*
		The result is a Number, which is the foldlevel of line {lnum}
		in the current buffer.  For nested folds the deepest level is
		returned.  If there is no fold at line {lnum}, zero is
		returned.  It doesn't matter if the folds are open or closed.
		When used while updating folds (from 'foldexpr') -1 is
		returned for lines where folds are still to be updated and the
		foldlevel is unknown.  As a special case the level of the
		previous line is usually available.
		{lnum} is used like with |getline()|.  Thus "." is the current
		line, "'m" mark m, etc.

                Parameters: ~
                  • {lnum} (`integer|string`)

                Return: ~
                  (`integer`)

foldtext()                                                          *foldtext()*
		Returns a String, to be displayed for a closed fold.  This is
		the default function used for the 'foldtext' option and should
		only be called from evaluating 'foldtext'.  It uses the
		|v:foldstart|, |v:foldend| and |v:folddashes| variables.
		The returned string looks like this: >
			+-- 45 lines: abcdef
<		The number of leading dashes depends on the foldlevel.  The
		"45" is the number of lines in the fold.  "abcdef" is the text
		in the first non-blank line of the fold.  Leading white space,
		"//" or "/*" and the text from the 'foldmarker' and
		'commentstring' options is removed.
		When used to draw the actual foldtext, the rest of the line
		will be filled with the fold char from the 'fillchars'
		setting.
		Returns an empty string when there is no fold.

                Return: ~
                  (`string`)

foldtextresult({lnum})                                        *foldtextresult()*
		Returns the text that is displayed for the closed fold at line
		{lnum}.  Evaluates 'foldtext' in the appropriate context.
		When there is no closed fold at {lnum} an empty string is
		returned.
		{lnum} is used like with |getline()|.  Thus "." is the current
		line, "'m" mark m, etc.
		Useful when exporting folded text, e.g., to HTML.

                Parameters: ~
                  • {lnum} (`integer|string`)

                Return: ~
                  (`string`)

foreach({expr1}, {expr2})                                            *foreach()*
		{expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
		For each item in {expr1} execute {expr2}. {expr1} is not
		modified; its values may be, as with |:lockvar| 1. |E741|
		See |map()| and |filter()| to modify {expr1}.

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

		If {expr2} is a |string|, inside {expr2} |v:val| has the value
		of the current item.  For a |Dictionary| |v:key| has the key
		of the current item and for a |List| |v:key| has the index of
		the 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}

Title: Vimscript Functions: `foldtext()`, `foldtextresult()`, and `foreach()`
Summary
This section details the `foldtext()` function, which returns the string displayed for a closed fold, using variables like `v:foldstart`, `v:foldend`, and `v:folddashes`. It then describes `foldtextresult()`, which returns the text displayed for a closed fold at a given line by evaluating the 'foldtext' option. Finally, the section explains `foreach()`, which iterates over items in a List, String, Blob, or Dictionary, executing a command or function for each item.