Change the next N characters in VIM

Use c{motion} command:

  1. cf_ - change up to the first '_' (including);
  2. ct_ - change up to the first '_' (excluding);
  3. cw - change the first word;

The word is determined by iskeyword variable. Check it with :set iskeyword? and remove any '_', like that :set iskeyword=@,48-57,192-255. By the way see :help c and :help motion if you want more.


I think 3cl is what you want. It changes 3 characters to the right. I'd type ct_del<esc>, but that's not what you asked


3s, "substitute 3 characters" is the same as c3l. 3cl and c3l should be the same, I don't know why you'd see the same character repeated. I'm also a fan of using t, e.g. ct_ as another poster mentioned, then I don't have to count characters and can just type "del".

I struggled with the "replace a couple of characters" for a few days too; 'r' was great for single characters, R was great for a string of matching length, but I wanted something like the OP is asking for. So, I typed :help x and read for a while, it turns out that the description of s and S are just a couple of pages down from x.

In other words, :help is your friend. Read and learn.

Tags:

Vim

Character