tags:

views:

487

answers:

4

In normal mode, I can hit "ce", 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)

Follow up question: How can I replace the current word with whatever's in the default register?

+5  A: 

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.

Hank Gay
this also deletes the space after the word. Should be `bPlde`.
0x89
No, should be `viwp`
Wahnfrieden
+24  A: 

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

Kaali
"caw" can be used in place of "ciw" same functionality.
jinxed_coder
Whereas 'caw' and 'ciw' will replace the entire word, simply 'cw' will change from the the current cursor position to the end of the current word.
Drew Stephens
I edited the answer from telling about "co{" to "ca{" as reminded by jinxed_coders comment. My old customization implements "(a) <>" commands as "(o)uter <>" commands.
Kaali
`ciw` and `caw` are not exactly the same: `ciw` deletes just the word, `caw` deletes the trailing space as well.
Roberto Bonvallet
A: 

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

ayaz
You can use `bcw` to go to the beginning of the current word then change the word, which leaves you insert mode.
Hank Gay
If your cursor is already on the first character of the word, that will end up deleting the previous word.
Warren Pena
+1  A: 

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.
too much php