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:
NddN= number of lines to deletedd= delete command
Example:
To delete 10 lines starting from the current line:
10ddSteps:
- Press
Escto ensure you’re in normal mode. - Type the number (
N) of lines you want to delete. - Then press
dandd.
For example:
Press → 1 0 d d
And you’re done — 10 lines gone in one shot!
