0

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?

  • Why is this, and so many of your other questions, tagges vimrc? What does the :s command have to do with vimrc? – muru Jul 16 '20 at 1:50
  • @muru I. think mostly because I don't know how to tag it / what aspect of vim it is, other than vimscript I suppose. – David542 Jul 16 '20 at 2:45
3

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 :&

  • 1
    is there a register or something that stores the last {pat} ? Or how do you see what that is? – David542 Jul 16 '20 at 1:29
  • There is: "\ holds the last search pattern. – Wolf Jul 16 '20 at 11:33
  • @Wolf last search pattern and last substitute pattern are different. There is no way to get the last substitute pattern as far as I know. – Mass Jul 16 '20 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.