How to delete a word and switch to insert mode in Vim?

In normal mode, I can press Ctrl + E , which deletes the rest of the current word and goes into insert mode.

I want to delete the entire word, regardless of the position of the cursor (within the word, of course).

+89
vim
Sep 04 '09 at 13:17
source share
5 answers

You can use "change inner word" by typing "ciw" to delete the word that your cursor is in.

The "inner" and "a" commands are great in Vim, also try "ci {" inside the block {} or "ca {" if you also want to remove the characters {}. To translate these commands into English, to better remember them, try: "change the internal {block] and" change {block].

Documentation at http://vimdoc.sourceforge.net/htmldoc/motion.html#text-objects

+154
Sep 04 '09 at 13:20
source share

Answer your next question: viwp

 v -> start visual mode iw -> select the 'inner word' p -> paste - in visual mode it replaces the visually selected text. 
+18
Sep 07 '09 at 4:50
source share

For the second question: bPldw

This will lead you to the beginning of the current word, insert the default case before the cursor, go to the next character (skipping the end of the text you just inserted), and delete the rest of the word.

+8
Sep 04 '09 at 13:20
source share

Or you could use the bdwi key bdwi to delete the current word and switch to INSERT mode.

+2
Sep 04 '09 at 13:23
source share

On the first question, bcw also works. This means " b ack to start a word, c hange w ord". But I think ciw more memorable, which means " c hange i nner w ord", is just one step away.

In the second question about β€œreplace using paste,” my solution is "_diwP . It is d elete i nner w ord to the register that you are not interested in, and p delay the contents of the default register. The advantage is that you can insert the default register many times because it will not be contaminated. It is a litte complex, so I display it as nnoremap ,r "_diwP .

+2
Apr 30 '15 at 6:41
source share



All Articles