p_duthoit
p_duthoit

Reputation: 328

Remove empty lines in file with VSCode but only at the start and end of file

Here is my text :

     <---- empty line to delete
     <---- empty line to delete
Lorem ipsum
Lorem ipsum
     <---- empty line to keep
Lorem ipsum
     <---- empty line to delete

Here's what I would like to have using VSCode regex, or any extension you might know about.

Lorem ipsum
Lorem ipsum

Lorem ipsum

Any idea ? Thanks!

EDIT: I might need to precise that I want to achieve this on more than 12000 files. So can't imagine doing this manually.. And I haven't found any extensions yet, neither answers about this subject.

Upvotes: 0

Views: 1143

Answers (1)

s_baldur
s_baldur

Reputation: 33498

For empty lines at the end, you can remove them with \n+$(?![\r\n]) in VSCode.

For the first empty lines should work (?) (?<!(.|\n))\n+.

Other flavours of regex have (although they don't seem to work in VSCode) have \A or \` and \Z \' for start and end of file.

Upvotes: 3

Related Questions