How to Delete Multiple Lines in vi Editor

ADVERTISEMENT

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 delete
  • dd = delete command

Example:

To delete 10 lines starting from the current line:

10dd

Steps:

  1. Press Esc to ensure you’re in normal mode.
  2. Type the number (N) of lines you want to delete.
  3. Then press d and d.

For example:

Press →  1  0  d  d

And you’re done — 10 lines gone in one shot!

ADVERTISEMENT

Leave a Reply

Your email address will not be published. Required fields are marked *