What does :s
by itself do? I was thinking that it would be equivalent to:
:s//
Does it use the equivalent of <C-r>/
or something, or where is it grabbing the pattern from?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityWhat does :s
by itself do? I was thinking that it would be equivalent to:
:s//
Does it use the equivalent of <C-r>/
or something, or where is it grabbing the pattern from?
Per vim's help*, :s
by itself,
[Repeats the] last :substitute with same search pattern and substitute string, but without the same flags.
This means vim will perform substitution like this :s/{pat}/{sub}/
, where pat
is the last substitute pattern, which is not exactly (as the help may imply) the same as the last search pattern stored in @/
. To emphasize the part about flags, if you had used global substitute like :s/a/b/g
, :s
would not be done with global set.
In contrast, s://
means use the last search pattern and replace with empty string.
Note the difference between :s
and :~
, which actually does use the last search pattern (like with /
), which then becomes the last substitute pattern also.
*:help :&
:s
command have to do with vimrc? – muru Jul 16 '20 at 1:50vimscript
I suppose. – David542 Jul 16 '20 at 2:45