2

for one single word, the job is quite easy: we just do a 'cw'

what if I select a certain text and I want to replace this block with one word?

obviously I can do a 'x' and then 'i', is there a one key-stoke solution?

in other words, after I select the block in visual mode, what is the fastest way to do 'delete' and then enter insert mode?

any idea?

3 Answers 3

4

You can do exactly this with c. From :help v_c:

{Visual}["x]c   or                  *v_c* *v_s*
{Visual}["x]s       Delete the highlighted text [into register x] and
            start insert (for {Visual} see |Visual-mode|).  {not
            in Vi}

In general, most commands that work in normal mode will work the same way in visual mode. So since you can do cw, you can do c in visual mode and it will have the same effect. Same for d, y, gu, etc.

3

You can do the selection using visual mode and then hit s or c to remove the selected text and directly enter insert mode.

2

First, you can enter visual mode V-Line Shift + v then select your code with j(down) or k (up). Then Shift + s will empty your block of code and enter insert mode.

Explanation:

  • Shift + v let you select entire lines.
  • Shift + s replace your selection and enters insert mode.

Now, an even better tip... if your code is between { and } and your cursor is placed inside those, then you can just type ci{ and it will leave everything inside { and } blank and enter insert mode.

Explanation:

  • c change
  • i internal
  • { delimiter, it can be ( or { or "

Here are both:

enter image description here

I hope this will help you. Cheers!

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.