How to delete empty line with vi

Reading Time: < 1 minute

How to delete empty lines with vi?

Just type this in:

 
<esc>:g/^$/d

NOTE:  This means that all the lines that just have a carriage return on them (NO Spaces), will be removed. 

If you want to remove lines with empty spaces as well:

 
<esc>:g/^ *$/d
Reading Time: < 1 minute

How to delete empty lines with vi?

Just type this in:

 
<esc>:g/^$/d

NOTE:  This means that all the lines that just have a carriage return on them (NO Spaces), will be removed. 

If you want to remove lines with empty spaces as well:

 
<esc>:g/^ *$/d

By Marc Olivier Meunier

Marc has spent the past few years putting oil on the fire of a hyper growth ad tech company. At Smartly.io he was in charge of scaling the support and its culture. At Eficode he is now leading an engineering team and running operations. He leads by example and puts a lot of emphasis on diversity and inclusion, constantly working to create a safe environment. A warm leader with a passion for memorable experiences and innovation.
Find Marc on Linkedin

Leave a Reply

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