How to remove empty lines in Visual Studio?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s very useful especially if you want to arrange or compare codes, thanks to the people who answer this question, I’ve got the answer from here and would like to share it with Stackoverflow:
Visual Studio (Visual Studio Code) has the ability to delete empty lines in replace operation using regular expressions.
Click Ctrl–H (quick replace)
Tick "Use Regular Expressions"
In Find specify
^$\nIn Replace box delete everything.
Click "Replace All"
All empty lines will be deleted.
Regular expression for empty line consists of
Beginning of line
^End of line
$Line break
\nNote that normally in Windows an end of line indicated by 2 characters crlf – Carriage Return (CR, ASCII 13,
\r) Line Feed (LF, ASCII 10,\n).A regex to remove blank lines that are/aren’t really blank (i.e. they do/don’t have spaces):
^:b*$\nTo remove double lines:
^:b*\n:b*\nreplace with:\n*** for Visual Studio 2013 and above:***
and for double lines:
See the regular expression syntax updates for VS2012 and above in @lennart’s answer below