How to delete a line in Vim
In this article, we will explore different ways to delete lines using Vim and discuss some tips and tricks for using this feature effectively.
You can use the dd
command to delete a single line in Vim. This command deletes the current line and places it into the clipboard, so you can paste it elsewhere if needed (with p
).
To delete multiple lines, you can use the n
modifier, followed by the dd
command. For example, you can use the 5dd
command to delete five lines, which will delete the current and four lines below.
Another way to delete lines in Vim is to use the d
command with a motion. A motion is a command that moves the cursor to a specific position in the text, such as the beginning or end of a line, a word, or a sentence. For example, the w
motion moves the cursor to the next word, and the $
motion moves the cursor to the end of the line.
To use a motion with the d
command, you simply type the d
command followed by the motion command. For example, to delete from the current cursor position to the end of the line, you can use the d$
command.