How to delete a word and go into insert mode in 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


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.


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.


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.

Tags:

Vim