How to delete a word and go into insert mode in Vim?

In normal mode I can hit Ctrl + E which deletes the rest of the current word and goes to insert mode.

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


Solution 1:

You can use "change inner word" by typing "ciw" to delete a word your cursor is on.

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

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

Solution 2:

Answer to your follow-up question: viwp

v    -> start visual mode
iw   -> select the 'inner word'
p    -> paste - in visual mode it replaces the visually selected text.

Solution 3:

For the second question: bPldw

This will, in order, take you to the beginning of the current word, insert the default register in front of the cursor, go to the next character (taking you past the end of the text you just inserted), and delete the rest of the word.

Solution 4:

For the first question, bcw also work. It means "back to the begin of word, change word". But I think ciw is more memorable, which means "change inner word", just only one step.

For the second question about "replace using paste", my solution is "_diwP. It delete inner word to a register you don't care and paste the default register's content. An advantage is that you can paste the default register many times, because it wouldn't be polluted. It's a litte complex so I map it as nnoremap ,r "_diwP.

Solution 5:

Or, you could perhaps use the key sequence bdwi to delete the current word and go into INSERT mode.