如何在 Vim 中删除一个单词并进入插入模式?

在正常模式下,我可以点击 强 > Ctrl + E ,它删除当前单词的其余部分,进入插入模式。

我想删除整个单词,不管光标的位置(当然在单词内)。

43590 次浏览

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.

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

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

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.

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.