13

What is the intended use case for the s command in normal mode?

I've been looking at it for some time, inadvertently pressing s, but can't find any use case that would make sense for me.

10

I don't think there's a more specific use mode than to delete the character under the cursor and enter insert mode. By using a number modifier you can delete several characters before entering insert mode. E.g. if you want to change foobar into fubar, then I would set to cursor to f, and press 3sfu. Of course, you don't need to use s, you could also do e.g. ctbu. I guess you can always get away without using s. That being said, I use s very often.

6
  • 1
    I use it to avoid "delete something then enter insert" separately. It's nice to be able to hit v for highlight, then 4e to highlight 4 words, then hit s and start typing.
    – user859
    Mar 29 '17 at 10:43
  • 1
    I don't use s that way because I don't like moving too often that far up the keyboard for editing stuff. I would use c for that. That being said, I was wondering if there's some other intended use case. It just fells against the vim way I got used to.
    – Dumitru
    Mar 29 '17 at 11:12
  • 1
    @Dumitru Can you touch type numbers? Cause that's the only reason I see to "don't like moving too ofthen that far up the keyboard". Mar 30 '17 at 21:32
  • @user1685095, Yeah, I can. What do you mean with the only reason? The inability or the ability?
    – Dumitru
    Mar 30 '17 at 21:50
  • @Dumitru Inability. Mar 30 '17 at 21:53
8

s is short for cl which is mentioned in help s:

["x]s                   Delete [count] characters [into register x] and start
                        insert (s stands for Substitute).  Synonym for "cl"
                        (not linewise).

I've mapped s to my own command and haven't missed the default 'substitute' so far.

3

In normal mode:

  • s same as cl
  • S same as cc
  • [count]s same as [count]cl or c[count]l
  • [count]S same as [count]cc

In visual mode:

  • s same as c
  • S is remapped by vim-surround to a (very useful) surround operator.

I don't see any clear advantage of having s for substitute when there is already a c for change. I'm testing with nmap s ys in my init.vim (or .vimrc) to use s as a surround operator.

1
  • Welcome to Vi and Vim! One use for s is to replace a single character with more characters (since r only works with one character replacements). That said, I rarely use it…
    – D. Ben Knoble
    Oct 11 at 18:49

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.