1

Given the following line

this is a testing line

When my cursor is on "a" and then I type 2s, it becomes

this is testing line

My cursor is on "t" of testing, and I am in insert mode.

Is there something like this that replaces words instead of letters and then puts you in insert mode?

Thanks

1
  • 1
    I think you are looking for ciw (change inner word) or ce (change to end of word). Please clarify as I am not sure exactly what you are asking for. I would suggest you run vimturor and start reading the manuals. I suggest start reading at :h usr_02.txt and continue though each chapter. Then use :h quickref if you need to find a motion/topic. Commented Mar 23, 2018 at 22:35

1 Answer 1

3

If you're asking whether there's a way to eliminate n words and drop into insert mode to conveniently replace them with something else, yes there is, with a few variations.

With your cursor on the a, you could do c2w (or 2cw) to remove a testing and drop into insert mode with your cursor before the space preceding line. This operation can also span multiple lines, so if you had your cursor on the a in

this is a testing line
and this is another one

and typed 5cw it would join the lines and drop you into insert mode with your cursor placed between is and is

this is  is another one

The w movement in this context encompasses characters from the cursor to the end of a word, so if you start from within a word, the beginning of the word will be unaffected. For example, with the cursor on the x

flexible stuff bends

typing c2w eliminates xible stuff and puts you insert mode with the cursor after the fle in fle bends. You could also have used e instead of w in all the previous examples and it would behave the same.

If you wanted to operate on the entire word instead, you could use caw or ciw. In the previous example, typing 2caw removes flexible stuff (including the following space) and puts you in insert mode with your cursor right before bends. ciw acts a bit differently, and it's easier to try it out and get a sense for it than for me to try to describe it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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