Home Explore Blog CI



neovim

20th chunk of `runtime/doc/vimfn.txt`
428801f1227d6ffa7ab566d6c1e0d22e7d4d59be1899f2f00000000100000fb6
 {noref} set to 1 every occurrence of a
		|List| or |Dictionary| results in a new copy.  This also means
		that a cyclic reference causes deepcopy() to fail.
								*E724*
		Nesting is possible up to 100 levels.  When there is an item
		that refers back to a higher level making a deep copy with
		{noref} set to 1 will fail.
		Also see |copy()|.

                Parameters: ~
                  • {expr} (`T`)
                  • {noref} (`boolean?`)

                Return: ~
                  (`T`)

delete({fname} [, {flags}])                                           *delete()*
		Without {flags} or with {flags} empty: Deletes the file by the
		name {fname}.

		This also works when {fname} is a symbolic link.  The symbolic
		link itself is deleted, not what it points to.

		When {flags} is "d": Deletes the directory by the name
		{fname}.  This fails when directory {fname} is not empty.

		When {flags} is "rf": Deletes the directory by the name
		{fname} and everything in it, recursively.  BE CAREFUL!
		Note: on MS-Windows it is not possible to delete a directory
		that is being used.

		The result is a Number, which is 0/false if the delete
		operation was successful and -1/true when the deletion failed
		or partly failed.

                Parameters: ~
                  • {fname} (`string`)
                  • {flags} (`string?`)

                Return: ~
                  (`integer`)

deletebufline({buf}, {first} [, {last}])                       *deletebufline()*
		Delete lines {first} to {last} (inclusive) from buffer {buf}.
		If {last} is omitted then delete line {first} only.
		On success 0 is returned, on failure 1 is returned.

		This function works only for loaded buffers. First call
		|bufload()| if needed.

		For the use of {buf}, see |bufname()| above.

		{first} and {last} are used like with |getline()|. Note that
		when using |line()| this refers to the current buffer. Use "$"
		to refer to the last line in buffer {buf}.

                Parameters: ~
                  • {buf} (`integer|string`)
                  • {first} (`integer|string`)
                  • {last} (`integer|string?`)

                Return: ~
                  (`any`)

dictwatcheradd({dict}, {pattern}, {callback})                 *dictwatcheradd()*
		Adds a watcher to a dictionary. A dictionary watcher is
		identified by three components:

		- A dictionary({dict});
		- A key pattern({pattern}).
		- A function({callback}).

		After this is called, every change on {dict} and on keys
		matching {pattern} will result in {callback} being invoked.

		For example, to watch all global variables: >vim
			silent! call dictwatcherdel(g:, '*', 'OnDictChanged')
			function! OnDictChanged(d,k,z)
			  echomsg string(a:k) string(a:z)
			endfunction
			call dictwatcheradd(g:, '*', 'OnDictChanged')
<
		For now {pattern} only accepts very simple patterns that can
		contain a "*" at the end of the string, in which case it will
		match every key that begins with the substring before the "*".
		That means if "*" is not the last character of {pattern}, only
		keys that are exactly equal as {pattern} will be matched.

		The {callback} receives three arguments:

		- The dictionary being watched.
		- The key which changed.
		- A dictionary containing the new and old values for the key.

		The type of change can be determined by examining the keys
		present on the third argument:

		- If contains both `old` and `new`, the key was updated.
		- If it contains only `new`, the key was added.
		- If it contains only `old`, the key was deleted.

		This function can be used by plugins to implement options with
		validation and parsing logic.

                Parameters: ~
                  • {dict} (`table`)
                  • {pattern} (`string`)
                  • {callback} (`function`)

                Return: ~
                  (`any`)

dictwatcherdel({dict}, {pattern}, {callback})                 *dictwatcherdel()*
		Removes a watcher added  with |dictwatcheradd()|.

Title: Vimscript Functions: Deep Copy, File Deletion, Buffer Line Deletion, and Dictionary Watchers
Summary
This section describes several Vimscript functions: It expands on deepcopy(), explaining the behavior with {noref} set to 1 and potential failures due to cyclic references. It details delete(), which deletes files and directories, including recursive deletion, and returns a status code. It also presents deletebufline(), which deletes lines from a buffer. The last function described is dictwatcheradd() and dictwatcherdel() that add/remove watchers to a dictionary, invoking a callback function when specified keys change, along with dictwatcherdel() which removes the watcher.