Home Explore Blog CI



neovim

9th chunk of `runtime/doc/change.txt`
d538e003580a0269a56ba3c6893c452343b954f06cd5b3cc0000000100000fa0
	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
			`:&r`.  See |:s_flags| for [flags].

								*&*
&			Synonym for `:s` (repeat last substitute).  Note
			that the flags are not remembered, thus it might
			actually work differently.  You can use `:&&` to keep
			the flags.

								*&-default*
			Mapped to ":&&<CR>" by default. |default-mappings|

								*g&*
g&			Synonym for `:%s//~/&` (repeat last substitute with
			last search pattern on all lines with the same flags).
			For example, when you first do a substitution with
			`:s/pattern/repl/flags` and then `/search` for
			something else, `g&` will do `:%s/search/repl/flags`.
			Mnemonic: global substitute.

						*:snomagic* *:sno*
:[range]sno[magic] ...	Same as `:substitute`, but always use 'nomagic'.

						*:smagic* *:sm*
:[range]sm[agic] ...	Same as `:substitute`, but always use 'magic'.

							*:s_flags*
The flags that you can use for the substitute commands:

							*:&&*
[&]	Must be the first one: Keep the flags from the previous substitute
	command.  Examples: >
		:&&
		:s/this/that/&
<	Note that `:s` and `:&` don't keep the flags.

[c]	Confirm each substitution.  Vim highlights the matching string (with
	|hl-IncSearch|).  You can type:				*:s_c*
	    'y'	    to substitute this match
	    'l'	    to substitute this match and then quit ("last")
	    'n'	    to skip this match
	    <Esc>   to quit substituting
	    'a'	    to substitute this and all remaining matches
	    'q'	    to quit substituting
	    CTRL-E  to scroll the screen up
	    CTRL-Y  to scroll the screen down

							*:s_e*
[e]     When the search pattern fails, do not issue an error message and, in
	particular, continue in maps as if no error occurred.  This is most
	useful to prevent the "No match" error from breaking a mapping.  Vim
	does not suppress the following error messages, however:
		Regular expressions can't be delimited by letters
		\ should be followed by /, ? or &
		No previous substitute regular expression
		Trailing characters
		Interrupted

							*:s_g*
[g]	Replace all occurrences in the line.  Without this argument,
	replacement occurs only for the first occurrence in each line.  If the
	'gdefault' option is on, this flag is on by default and the [g]
	argument switches it off.

							*:s_i*
[i]	Ignore case for the pattern.  The 'ignorecase' and 'smartcase' options
	are not used.

							*:s_I*
[I]	Don't ignore case for the pattern.  The 'ignorecase' and 'smartcase'
	options are not used.

							*:s_n*
[n]	Report the number of matches, do not actually substitute.  The [c]
	flag is ignored.  The matches are reported as if 'report' is zero.
	Useful to |count-items|.
	If \= |sub-replace-expression| is used, the expression will be
	evaluated in the |sandbox| at every match.

[p]	Print the line containing the last substitute.  *:s_p*

[#]	Like [p] and prepend the line number.  *:s_#*

[l]	Like [p] but print the text like |:list|.  *:s_l*

							*:s_r*
[r]	Only useful in combination with `:&` or `:s` without arguments.  `:&r`
	works the same way

Title: Vim: Substitute Command Flags and Variations
Summary
This section elaborates on the various flags and variations of the `:substitute` command in Vim. It explains how to repeat substitutions using `:&` and `:~`, including how to retain or modify flags from the previous substitution. It also covers the `snomagic` and `smagic` variations, which force 'nomagic' or 'magic' mode respectively. The section provides detailed explanations of the available flags like 'c' (confirm), 'e' (no error), 'g' (global), 'i' (ignore case), 'I' (don't ignore case), 'n' (report number of matches), 'p' (print), '#' (print with line number), 'l' (print like :list), and 'r' (use with :& to repeat).