How to Delete Multiple Lines in vi Editor
When you’re editing a file in vi
(or vim
) and come across a large block of unnecessary lines—such as logs, commented code, or config entries—you might want to delete several lines at once.
Instead of deleting them one by one, you can remove N lines instantly from your current cursor position.
Command Format:
Ndd
N
= number of lines to deletedd
= delete command
Example:
To delete 10 lines starting from the current line:
10dd
Steps:
- Press
Esc
to ensure you’re in normal mode. - Type the number (
N
) of lines you want to delete. - Then press
d
andd
.
For example:
Press → 1 0 d d
And you’re done — 10 lines gone in one shot!