delete empty lines in visual studio

programmers write a lot of text. better yet, they write structured text. that’s where regular expressions become handy. from time to time there are a lot of repetitive tasks, like deleting hundreds of empty lines out of an source file in VisualStudio 2005.

To get rid of them all press CTRL+H (the default hotkey) to fire up the search+replace dialog. In the find options select Use: Regular expressions as the search method. In the search textfield enter ^$\n and leave the replace with text field empty. Select the scope where search+replace should take place in the “Look in” drop down box. Now, fire away.

search_replace

As a short hint as to what the expression actually means:
^ = match the beginning of an line
$ = match the end of a line, but not the linefeed character
\n = match the linefeed


About this entry