# Guide: Delete One/Multiple Lines in Vi and Vim

**URL:** https://www.compsmag.com/blogs/guide-delete-one-multiple-lines-in-vi-and-vim/
**Author:** Ayushi Chauhan
**Published:** 2021-11-18
**Updated:** 2021-11-18
**Categories:** Blogs
**Tags:** Blogs Daily, Computer Guides, guiderobert, Guides and Tutorials, guiding12, How To Guide, Linux Guides, Tips, Tricks
**Reading Time:** 3 min

---

This guide is about Guide: Delete One/Multiple Lines in Vi and Vim. So read this free guide, Guide: Delete One/Multiple Lines in Vi and Vim step by step. If you have query related to same article you may contact us.

## Guide: Delete One/Multiple Lines in Vi and Vim - Guide

Vim, formerly known as Vi, stands for “Vi IMproved” and is a multi-purpose text editor compatible with all UNIX-based operating systems such as Linux and macOS.  Vim can be used for various purposes, such as: B. to create, edit text and/or computer program files.  You often need to delete one or more lines when editing text files in the Vim editor, and unlike any other text editor, you can edit your files very efficiently.  This guide will focus on editing and deleting lines from your files in the Vim editor.

## Deleting a Line

The command to delete a line in Vim is dd.  Below are step-by-step instructions for deleting a row:

Press Esc key to go to normal mode.

Position the cursor on the line you want to delete.

Type dd and press Enter to remove the line.

Pressing dd multiple times will delete multiple lines.

## Excluding multiple lines

To delete multiple lines at once, precede the dd command with the number of lines to be deleted.  For example, to delete five lines, you would do the following:

Press Esc key to go to normal mode.

Position the cursor on the first line you want to delete.

Type 5dd and press Enter to delete the next five lines.

## Delete a range of lines

The syntax for excluding a range of lines is as follows: For example, to exclude lines starting from 3 to 5, you would do the following:

Press Esc key to go to normal mode.

Type: 3.5d and press Enter to delete the lines.

You can also use the following characters to specify the range:

.  (dot) - The current line.

$ - the last line.

% - all lines.

## delete all lines

To exclude all rows, you can use the % symbol representing all rows or the range 1, $:

Press Esc key to go to normal mode.

Type %d and press Enter to delete all lines.

## Deleting lines containing a pattern

The syntax for deleting multiple lines based on a specific pattern is as follows:

The global command (g) tells the delete command (d) to delete all lines that contain the .  To match lines that don't match the pattern, add an exclamation point (!) before the pattern:

## Final note

I hope you like the guide Guide: Delete One/Multiple Lines in Vi and Vim. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.

---

*End of Article*