How do I delete a word when the cursor is somewhere in the middle of that word (neither at the end or beginning of a word) in Vim?
Press [CTRL]-[BACKSPACE] - to delete one word from the left of the cursor. Press [SHIFT]-[END]- [BACKSPACE] - to delete all text from the insertion point (where the cursor is) to the end of the line.
Both the Del or Delete key and Backspace key can delete text. However, when dealing with text, pressing the Del deletes text to the right of the cursor. Pressing Backspace deletes text to the left (backwards) of the cursor.
[Ctrl]+[Delete] Pressing [Delete] removes the characters to the right of the insertion point, one character at a time. To delete several characters to the right, at once, press [Ctrl]+[Delete]. This combo deletes all the characters to the right of the insertion point in the current word.
Keep the insertion point just before the word you want to delete and press Ctrl + Delete key. Word deletes the word immediately to the right of the insertion point.
What you need is the following keystrokes in normal mode (after pressing Esc):
diw (meaning: delete inner word)
-or-
daw (meaning: delete a word)
The second command also deletes all spaces after the word, or all spaces before the word if there are no spaces after the word.
For more related commands:
:help diw :help daw
I found that "diw" ( delete inner word ) is the straight forward way to delete a word!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With