Delete multiple lines in VI / VIM editor

Do not miss this exclusive book on Binary Tree Problems. Get it now for free.

In this article, we have explained how to delete multiple lines in VI / VIM editor in an UNIX system like Ubuntu along with an example.

Table of contents:

  1. Delete one line in VI / VIM editor
  2. Delete multiple lines in VI / VIM editor
  3. Example

Delete one line in VI / VIM editor

The process to delete one line in vi / vim editor is:

  • Press ESC key to get into escape mode.
  • Go to the line from which you want to delete
  • Press "dd" (press d key two times)
  • The current line will be deleted.

Delete multiple lines in VI / VIM editor

To delete multiple lines in vi / vim editor, following the following steps:

  • Press ESC key to get into escape mode.
  • Go to the line from which you want to delete X lines (current line included).
  • Type the number of lines you want to delete from the current position (the number will appear at the bottom right corner) followed by "dd" (press d key two times)
  • X lines will be deleted.

Example

If you want to delete lines 52 to 107 (both included), then follow the following steps:

  • Press ESC key.
  • Go to line 52 by pressing ":" key, type 52 followed by ENTER key.
  • We need to delete 107-52+1 = 56 lines.
  • Type "56" followed by d key twice ("dd").
  • Lines 52 to 107 will be deleted.

With this article at OpenGenus, you must have the complete idea of how to delete multiple lines in VI or VIM editor in UNIX systems.

Sign up for FREE 3 months of Amazon Music. YOU MUST NOT MISS.