What is the difference between s, c and r commands in vi/vim?

lalit picture lalit · May 7, 2013 · Viewed 28.7k times · Source

I am trying to clarify this from the OReilly book on Vim, but the examples presented aren't clear enough. Clarification via examples/use-cases instead of direct explanation would be very helpful.

The Sample text could be:

With a
screen editor,
you can
scroll the page, move the cursor.

Answer

chirlu picture chirlu · May 7, 2013

Assume you have foo in the document, and the cursor is on the f.

Now, pressing rb will change this to boo, and you are back in command mode. Pressing sb will accomplish the same, but you are in insert mode and can insert more characters. Finally, c requires some kind of motion; e.g. you can type cw to remove the whole word and enter insert mode. On the other hand, cl is essentially the same as s.