Techolac - Computer Technology News
  • Home
  • Internet
  • Business
  • Computers
  • Gadgets
  • Lifestyle
  • Phones
  • Travel
  • Tech
  • More
    • Automotive
    • Education
    • Entertainment
    • Health
    • SEO
    • Linux
    • WordPress
    • Home Improvement
    • How to
    • Games
No Result
View All Result
  • Home
  • Internet
  • Business
  • Computers
  • Gadgets
  • Lifestyle
  • Phones
  • Travel
  • Tech
  • More
    • Automotive
    • Education
    • Entertainment
    • Health
    • SEO
    • Linux
    • WordPress
    • Home Improvement
    • How to
    • Games
No Result
View All Result
Techolac - Computer Technology News
No Result
View All Result
Home Linux

How to Delete Line in VIM

by Editorial Staff
November 17, 2018
in Linux
Reading Time: 3 mins read

[ad_1]

How to delete lines from Vim? How to delete ranges of lines? How to delete lines by a given pattern? Let’s cover in this article different ways to delete lines in Vim editor.

    1. Delete a single line
    2. Delete all lines
    3. Delete multiple lines
    4. Delete a range of lines
    5. Delete lines by a given pattern

Install Vim in Ubuntu/Debian distributions

# sudo apt install vim

Install Vim in RHEL/CentOS distributions

# yum install vim

1) Delete a single line

To delete a single line in Vim editor, follow the steps below

  1. Place the cursor to the beginning of the line
  2. Press the ESC key.
  3. Next, press dd  i.e quick press letter ‘ d ‘  twice in quick succession.

In the example below, pressing dd at the beginning of line 6 as shown below will delete the entire line.

delete lines in vim command

2) Delete all lines

Below are the two ways to delete all lines.

:1,$d

or

:%d

3) Delete multiple lines

To delete multiple lines

  1. place the cursor at the beginning of a line.
  2. Prefix the dd command with the number of lines you want to delete below it. For example, if you want to delete 3 consecutive lines below line 3 press
    # 3dd

delete lines in vim

4) Delete a range of lines

If you want to delete a range of lines, say from line 3 to line 5, the syntax is as shown below

:[start_line_no],[end_line_no]d

In this case, Press ESC  Then type the command below and hit Enter.

:3,5d

To delete the last line

:$d

To delete all lines before the current line

:1,.-1d

To delete all lines after the current line

:.+1,$d

5) Delete lines by a given pattern

Finally, you can delete lines following a given pattern.

For instance,  to delete lines that contain a certain word, press ESC and run

:g /word/d

In our case, to delete lines that contain the word “lazy”

:g /lazy/d

To delete every line that doesn’t contain the word “lazy”

See also  How to Generate sosreport on Ubuntu 18.04 / Debian 9 Server

:%g!/lazy/d
or
:v/lazy/d

To delete lines that begin with a certain letter, say ‘A’

:g/^A/d

If you want to delete lines that begin with a special character like $ sign, prefix the character with a backslash as shown

:g/^$/d

To get rid of all blank lines

:g/^$/d

Do you have any tips to delete vim lines? Hope this article helped you and please leave your comments.

Read Also:

[ad_2]

Related Posts

Top Commands to Check the Running Processes in Linux
Linux

Top Commands to Check the Running Processes in Linux

May 27, 2022
4 Tips to Prevent and Troubleshoot the ImagePullBackOff Kubernetes Error
Linux

4 Tips to Prevent and Troubleshoot the ImagePullBackOff Kubernetes Error

March 30, 2022
How Common Signals are Used in Kubernetes Pod Management
Linux

How Common Signals are Used in Kubernetes Pod Management

November 20, 2021

Leave a Reply Cancel reply

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

4 Ways to Secure a Better Future for Yourself

4 Ways to Secure a Better Future for Yourself

July 6, 2022
28 HDOnline Alternatives To Watch Movies And TV Shows Online

28 HDOnline Alternatives To Watch Movies And TV Shows Online

July 5, 2022
Top 26 Best NYAA Alternatives To Watch Anime Free

Top 26 Best NYAA Alternatives To Watch Anime Free

July 4, 2022
30 VUDU Alternatives To Watch Movies And TV Shows Online

30 VUDU Alternatives To Watch Movies And TV Shows Online

July 3, 2022
finland web hosting reviews

Top 10 Finland Web Hosting Reviews 2022

July 3, 2022
  • DashTech
  • TechDaddy
  • Terms and Conditions
  • Disclaimer
  • Write for us

© Techolac © Copyright 2019 - 2022, All Rights Reserved.

No Result
View All Result
  • Home
  • Internet
  • Business
  • Computers
  • Gadgets
  • Lifestyle
  • Phones
  • Travel
  • Tech
  • More
    • Automotive
    • Education
    • Entertainment
    • Health
    • SEO
    • Linux
    • WordPress
    • Home Improvement
    • How to
    • Games

© Techolac © Copyright 2019 - 2022, All Rights Reserved.

Go to mobile version