Home Explore Blog CI



neovim

97th chunk of `runtime/doc/vimfn.txt`
c4d2c52dcf818bd5378e07b5e45aeb31c90f8626f228c1e70000000100000fb2
 error.

                Parameters: ~
                  • {directory} (`string`)
                  • {expr} (`integer?`)

                Return: ~
                  (`any`)

readfile({fname} [, {type} [, {max}]])                              *readfile()*
		Read file {fname} and return a |List|, each line of the file
		as an item.  Lines are broken at NL characters.  Macintosh
		files separated with CR will result in a single long line
		(unless a NL appears somewhere).
		All NUL characters are replaced with a NL character.
		When {type} contains "b" binary mode is used:
		- When the last line ends in a NL an extra empty list item is
		  added.
		- No CR characters are removed.
		Otherwise:
		- CR characters that appear before a NL are removed.
		- Whether the last line ends in a NL or not does not matter.
		- Any UTF-8 byte order mark is removed from the text.
		When {max} is given this specifies the maximum number of lines
		to be read.  Useful if you only want to check the first ten
		lines of a file: >vim
			for line in readfile(fname, '', 10)
			  if line =~ 'Date' | echo line | endif
			endfor
<		When {max} is negative -{max} lines from the end of the file
		are returned, or as many as there are.
		When {max} is zero the result is an empty list.
		Note that without {max} the whole file is read into memory.
		Also note that there is no recognition of encoding.  Read a
		file into a buffer if you need to.
		Deprecated (use |readblob()| instead): When {type} contains
		"B" a |Blob| is returned with the binary data of the file
		unmodified.
		When the file can't be opened an error message is given and
		the result is an empty list.
		Also see |writefile()|.

                Parameters: ~
                  • {fname} (`string`)
                  • {type} (`string?`)
                  • {max} (`integer?`)

                Return: ~
                  (`string[]`)

reduce({object}, {func} [, {initial}])                           *reduce()* *E998*
		{func} is called for every item in {object}, which can be a
		|String|, |List| or a |Blob|.  {func} is called with two
		arguments: the result so far and current item.  After
		processing all items the result is returned.

		{initial} is the initial result.  When omitted, the first item
		in {object} is used and {func} is first called for the second
		item.  If {initial} is not given and {object} is empty no
		result can be computed, an E998 error is given.

		Examples: >vim
			echo reduce([1, 3, 5], { acc, val -> acc + val })
			echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
			echo reduce(0z1122, { acc, val -> 2 * acc + val })
			echo reduce('xyz', { acc, val -> acc .. ',' .. val })
<

                Parameters: ~
                  • {object} (`any`)
                  • {func} (`fun(accumulator: T, current: any): any`)
                  • {initial} (`any?`)

                Return: ~
                  (`T`)

reg_executing()                                                *reg_executing()*
		Returns the single letter name of the register being executed.
		Returns an empty string when no register is being executed.
		See |@|.

                Return: ~
                  (`any`)

reg_recorded()                                                  *reg_recorded()*
		Returns the single letter name of the last recorded register.
		Returns an empty string when nothing was recorded yet.
		See |q| and |Q|.

                Return: ~
                  (`any`)

reg_recording()                                                *reg_recording()*
		Returns the single letter name of the register being recorded.
		Returns an empty string when not recording.  See |q|.

                Return: ~
                  (`any`)

reltime()                                                            *reltime()*
reltime({start})
reltime({start}, {end})
		Return an item that represents a time value.  The item is a
		list with items that depend on the system.
		The item can be passed to |reltimestr()| to convert

Title: File Reading with `readfile()`, List Reduction with `reduce()`, and Register Information Functions
Summary
This section describes the `readfile()`, `reduce()`, `reg_executing()`, `reg_recorded()`, and `reg_recording()` functions. `readfile()` reads a file into a List of lines, with options for binary mode and line limits. `reduce()` applies a function cumulatively to the items of a String, List, or Blob. The register functions provide information about the currently executing, last recorded, and being recorded registers, respectively.