简体   繁体   中英

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

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

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

或者,您也许可以使用键序列bdwi来删除当前单词并进入INSERT模式。

For the first question, bcw also work. It means " b ack to the begin of word, c hange w ord". But I think ciw is more memorable, which means " c hange i nner w ord", just only one step.

For the second question about "replace using paste", my solution is "_diwP . It d elete i nner w ord to a register you don't care and p aste 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM