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

Vim

Vim Problem Overview


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).

Vim Solutions


Solution 1 - Vim

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 - Vim

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 - Vim

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 - Vim

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 - Vim

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJoernsnView Question on Stackoverflow
Solution 1 - VimKaaliView Answer on Stackoverflow
Solution 2 - Vimtoo much phpView Answer on Stackoverflow
Solution 3 - VimHank GayView Answer on Stackoverflow
Solution 4 - VimJustme0View Answer on Stackoverflow
Solution 5 - VimayazView Answer on Stackoverflow