in

LinuxLinux

How to Delete Line in Vim Editor on Linux Using Terminal Command!

Easy ways to delete lines in Vim Editor!

Delete Line in Vim Editor

D

elete lines in Vim Editor: Vim is one of the best Text Editor for Linux. You can create a new file, edit and save the files in the desired format. In this tutorial, we explained the easy steps to delete the lines in the Vim Text Editor on Linux Terminal. Let’s get into the article,

Jump To:

Install Vim Editor in Linux:

Vim is the best text editor for Linux, You can install it using the below command,

$sudo apt install vim

It will ask you to enter the password, enter it and finish the installation process.

Delete a Single Line in Vim Editor:

It is very easy to delete the single line in Vim Editor through the Command Terminal, Follow the below steps,

  • Place the cursor to the beginning of the line that you want to delete
  • Now press the ESC key
  • Press the letter ‘d’ twice quickly, dd
  • The above process will delete the line.

Example:

In the below video, we showed the working of dd to delete the single line.

Delete All Lines in Vim Editor:

You can delete all the lines in the Vim editor, Use the below command:

  • Click ESC key
  • Enter :%d or :1,$d
  • Hit Enter button, Instantly all the lines will delete in the vim editor.
Check this too  50+ Linux Command Sheet List for Newbies!

Example:

The below video explains, how to delete All Lines in Vim editor:

Delete Multiple Lines in Vim Editor:

You can perform deleting multiple lines in Vim editor, follow the below instructions:

  • Place the cursor at the beginning of the line that you want to delete
  • Click the ESC key
  • If you want to delete 4 multiple concurrent lines and then type the command 4dd & hit Enter button.

Example:

The below video explains, how to delete multiple lines in Vim editor:

Delete the Desired Range of Line in Vim Editor:

You can delete the desired range of line in Vim editor, follow the below instructions:

  • If you want to delete the lines between 2 to 6, then use the command :2,6d

Delete the last line:

You can delete the last line in the vim editor using the command su_label type=”black”]:$d[/su_label]

Delete all lines before the current line:

You can delete the last line before the current line using :1,.-1d, before that, you need to place the cursor in the current line.

Delete all lines after the current line:

You can delete the last line after the current line using :.+1,$d, before that, you need to place the cursor in the current line.

Delete lines which match the pattern:

You can delete the lines using conditions, follow the instruction below:

Delete the lines which contain the desired word:

You can delete the whole line which contains the specific word that matches with your pattern, use the command to delete lines:

:g /Hello/d– Command, deletes the line which contain the word “Hello” in it.

Check this too  Wget Command in Linux: Wget Command Syntax, Options & Examples!

Delete the lines which not matches with the desired word:

You can delete the lines which do not matches the given word.

:%g!/Hello/d– Command, deletes the lines which don’t contain the word “Hello” in it.

Delete the lines which start with the desired letter:

You can delete the lines which start with the desired letter in the lines. Use the command,

:g/^B/d– Command, deletes the lines which starts with the letter “B” in it.

Delete the lines begin with the symbol:

You can delete the lines which start with the desired symbol in the lines. Use the command,

:g/^\#/d– Command, deletes the lines which starts with the symbol “#” in it.

Delete all blank lines:

You can delete all the blank lines in the Vim Editor, Use the command:

:g/^$/d– Command, deletes all the empty lines in the Vim editor.

Verdict:

That’s it, These are the simplest ways to Delete single lines, multiple lines, all lines, lines match the pattern and empty lines in Vim editor. If you have any query related to this topic, then comment us below.

Article Explanation
  • Content Explanation
  • Commands Provided
  • Examples Provided
4.9

Summary

For more articles, Kindly visit our HomePage

Leave a Reply

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

Written by Rachel

I'm Rachel, From Arizona. Am playing the "Content Management" Role in Tec Robust. I started working in TR from Jan 2019. Big Marvel Fan.

Contact me:
tecrobust [@] gmail.com
Sub: Message to Rachel

Node-Red Ubuntu

Node Red Ubuntu- How to Install on Linux Ubuntu 18.04 LTS & 19.04, & More

Gitkraken Ubuntu

Gitkraken Ubuntu- How To Install Gitkraken on Ubuntu 18.04 LTS & 19.04