TransWikia.com

What does :s (by itself) do?

Vi and Vim Asked on August 31, 2021

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?

One Answer

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

Correct answer by Mass on August 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP