How to remove / delete lines in vim?



In this post, we quickly look at how to delete lines for different use cases in the command mode (using ESC).


How to delete a singlie line?

- Move cursor to the line we want to delete
- Use one of the following commands to delete the current line

dd

D


How to delete several lines?

- Move cursor to the first line of those lines we want to delete
- Use the command,e.g., when deleting 5 lines. You can change the number 5 to whatever you want

5dd


How to delete m-th to n-th lines?

- We can use the command for deleting 111th to 222th lines

:111,222d


How to delete from current line onwards to the end of the document?

- We can use the command below

:.,$d


How to delete from the beginning of the document to the current line?

- We can use the command below

:dgg


How to delete a singlie word?

- Move cursor to the beginning of the word we want to delete
- Use the command

dw

No comments:

Post a Comment