Home Explore Blog CI



neovim

8th chunk of `runtime/doc/change.txt`
87b11c858b009a3219acc4a01586117904151c56a13bbaf70000000100000fa0
 {filter} (for {Visual} see |Visual-mode|).

:{range}![!]{filter} [!][arg]				*:range!*
			For executing external commands see |:!|

			Filter {range} lines through the external program
			{filter}.  Vim replaces the optional bangs with the
			latest given command and appends the optional [arg].
			Vim saves the output of the filter command in a
			temporary file and then reads the file into the buffer
			|tempfile|.  Vim uses the 'shellredir' option to
			redirect the filter output to the temporary file.
			However, if the 'shelltemp' option is off then pipes
			are used when possible (on Unix).
			When the 'R' flag is included in 'cpoptions' marks in
			the filtered lines are deleted, unless the
			|:keepmarks| command is used.  Example: >
				:keepmarks '<,'>!sort
<			When the number of lines after filtering is less than
			before, marks in the missing lines are deleted anyway.

							*=*
={motion}		Filter {motion} lines through the external program
			given with the 'equalprg' option.  When the 'equalprg'
			option is empty (this is the default), use the
			internal formatting function |C-indenting| and
			|'lisp'|.  But when 'indentexpr' is not empty, it will
			be used instead |indent-expression|.

							*==*
==			Filter [count] lines like with ={motion}.

							*v_=*
{Visual}=		Filter the highlighted lines like with ={motion}.


						*tempdir* *tempfile* *setuid*
Nvim uses temporary files for filtering and generating diffs. Plugins also
commonly use |tempname()| for their own purposes. On the first request for
a temporary file, Nvim creates a common directory (the "Nvim tempdir"), to
serve as storage for all temporary files (including `stdpath("run")` files
|$XDG_RUNTIME_DIR|) in the current session.

The Nvim tempdir is created in the first available system tempdir:
	Unix:    $TMPDIR, /tmp, current-dir, $HOME.
	Windows: $TMPDIR, $TMP, $TEMP, $USERPROFILE, current-dir.

On unix the tempdir is created with permissions 0700 (only accessible by the
current user) to avoid security problems (e.g. symlink attacks).  On exit,
Nvim deletes the tempdir and its contents.
							*E5431*
If you see an error or |log| message like: >
	E5431: tempdir disappeared (2 times)
this means an external process on your system deleted the Nvim tempdir.
Typically this is caused by "antivirus" or a misconfigured cleanup service.

If Nvim has the setuid bit set this may cause problems: the temp file
is owned by the setuid user but the filter command probably runs as the
original user.


4.2 Substitute						*:substitute*
							*:s* *:su*
:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]
			For each line in [range] replace a match of {pattern}
			with {string}.
			For the {pattern} see |pattern|.
			{string} can be a literal string, or something
			special; see |sub-replace-special|.
			When [range] and [count] are omitted, replace in the
			current line only.  When [count] is given, replace in
			[count] lines, starting with the last line in [range].
			When [range] is omitted start in the current line.
							*E939* *E1510*
			[count] must be a positive number (max 2147483647)
			Also see |cmdline-ranges|.

			See |:s_flags| for [flags].
			The delimiter doesn't need to be /, see
			|pattern-delimiter|.

:[range]s[ubstitute] [flags] [count]
:[range]&[&][flags] [count]					*:&*
			Repeat last :substitute with same search pattern and
			substitute string, but without the same flags.  You
			may add [flags], see |:s_flags|.
			Note that after `:substitute` the '&' and '#' flags
			can't be used, they're recognized as a pattern
			separator.
			The space between `:substitute` and the 'c', 'g',
			'i', 'I' and 'r' flags isn't required, but in scripts
			it's a good idea to keep it to avoid confusion.
			Also see the two and three letter commands to repeat
			:substitute below |:substitute-repeat|.

:[range]~[&][flags] [count]					*:~*
			Repeat last substitute with same substitute string
			but with last used search pattern.  This is like
		

Title: Vim: Filter Commands, Temporary Files, and Substitute
Summary
This section details how to use filter commands in Vim, particularly the '={motion}' command with the 'equalprg' option. It explains how Vim handles temporary files for filtering and diff operations, including the creation of a temporary directory and the potential issues with setuid and external processes deleting the tempdir. Finally, the section covers the ':substitute' command for replacing text within a specified range, including details on patterns, strings, flags, and repeating previous substitutions.