Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete 4 words before cursor in vim?

Tags:

vim

I would also like to know if there are other ways to delete 4 words after the cursor.

I know 4de and 4dw delete 4 words after the cursor and 4db will delete 4 words in front of the cursor, but when I'm in the middle of a word like below:

// SO|ME RANDOM CODE HERE

the result from running 4de and 4dw is:

// SO|

instead of deleting all 4 words.

Thanks for any help!

like image 398
Alex Cory Avatar asked Apr 10 '14 07:04

Alex Cory


People also ask

How do I delete multiple words in Vim?

Deleting Multiple Lines Press the Esc key to go to normal mode. Place the cursor on the first line you want to delete. Type 5dd and hit Enter to delete the next five lines.

How do I delete old words in Vim?

d^ will delete from current backward to first non-white-space character. d0 will delete from current backward to beginning of line. dw deletes current to end of current word (including trailing space) db deletes current to beginning of current word.

How do I delete a specific string in Vim?

In order to delete lines matching a pattern in a file using vim editor, you can use ex command, g in combination with d command. To remove lines that contains the string amos , in vim command mode, type the command below and press Enter. This will delete all lines containing the specified keywords.


1 Answers

4dw deletes using a text motion: it is four times "delete from here to where I jump by w", which deletes the end of the word four times.

Use text objects instead: 4daw is four times "delete a word", or delete four words.

like image 65
Amadan Avatar answered Sep 22 '22 19:09

Amadan