Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delete a word when the cursor is in the middle of the word?

Tags:

vim

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?

like image 467
abubacker Avatar asked Apr 29 '10 12:04

abubacker


People also ask

How do I remove a word behind my cursor?

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.

How do I get rid of text to the right of my cursor?

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.

What is the shortcut key to delete word to right of 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.

How do you remove words from text?

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.


2 Answers

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 
like image 148
Zhaojun Avatar answered Sep 22 '22 08:09

Zhaojun


I found that "diw" ( delete inner word ) is the straight forward way to delete a word!

like image 23
abubacker Avatar answered Sep 23 '22 08:09

abubacker