English
+370 5 205 5502 sales@monovm.com

How to Delete line in Vim/Vi Editor? [Vim Delete Line]

While working you have to delete a line in the vim/vi editor, So you can follow the below-listed command VIM delete line command inside the articles that will guide you on how to delete single, multiple lines in VIM/VI Editor.

31 May, 22 by Susith Nonis 3 min Read

List of content you will read in this article:

Vim may be used to create, and modify text and computer program files for different reasons. When processing text files in the vim editor, you frequently have to remove one or more lines, and it allows you to easily modify your files, as does any other text editor. As there are various methods to delete a line in this popular text editor listed below. This article concentrates to help you with the VIM delete line command or how to delete multiple lines or vim delete all lines.

1. How to delete Single Line in Vi Editor

dd is the Vim command for deleting a line.

The following are detailed steps for deleting a line:

  1. To return to normal mode, use the Esc key.
  2. Place your pointer on the line you'd like to remove.
  3. To delete a single line, type dd and press the Enter button.

Numerous presses of the dd key will erase multiple lines.

2. How to delete a Single Word in vim/vi editor

  1. To return to normal mode, use the Esc key.
  2. To erase a term, place your cursor at the beginning of the term you want to remove.
  3. Make the following keystrokes: dw

3. How to remove multiple lines in vim?

Prefix the dd command and mention the number of lines to be erased to delete several lines at once. To remove five lines, for example, perform the following:

  1. To return to regular mode, use the Esc key.
  2. Place your cursor on the first line you'd like to remove.
  3. To remove the following six lines, type 6dd and press Enter.

4. How to Remove a group of lines from a document

  1. In Vim, press the Esc key to return to normal mode.
  2. When executing the following command, replace [from] and [to] with the line numbers where you want the array to start and end, respectively.

:[from],[to]d

For example, if you wanted to erase lines 3,4,5,6 and 7, you'd type:

:3,7d

5. How to Delete all Line

  1. You may use either the percent sign (which indicates all lines) or the 1,$ range to remove all lines:
  2. To return to normal mode, use the Esc key.
  3. To remove all the lines, type % d, and press Enter.

6. How to Delete Pattern-Containing Lines

The following is the syntax for removing several lines based on a pattern:

:g/<pattern>/d

The delete command (d) is told to remove all lines bearing the <pattern> by the global command (g).

For lines that do not suit the pattern, add an exclamation point (!) before the pattern:

:g!/<pattern>/d

7. How to Delete blank lines in VIM/VI

1. To return to normal mode, use the Esc key. and remove all blank lines.

2. After that, type the following:

:g/^$/d

Vim is one of the best and most popular editors in the Linux operating system. It's a text editor that's free, well-documented, and configurable. In this tutorial, we have learned how to delete line in Vim text editor or how to delete single words, multiple lines, or specific patterns in the VI editor. Vim is a powerful text editor with many more capabilities to discover. also if you think there are any text editors that we can use you can suggest them via the below comment section, you can read our detailed article that has a comparison between two popular text editors that are Vim vs. Nano text editors.

People also read: 

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I veture into the world of Technology I try to share what I know in the simplest way possible. Not a fan of coffee, a sweet addict and a self accredited 'master chef'.