Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyboard shortcut to remove empty lines in a C# code file

Is there any keyboard shortcut to remove empty lines in C# code files (.cs)?

Similar to Ctrl + K , D which formats the whole .cs file.

Or is there a workaround?

like image 529
indiPy Avatar asked Nov 30 '10 10:11

indiPy


2 Answers

Use the Find and Replace dialog (Ctrl + H). Search for

\n\n

and replace with

\n

using regular expressions (expand the Find Options section to enable).

If you want to remove lines containing nothing but whitespace you could try searching for

\n\s*\n+
like image 163
Ed Guiness Avatar answered Oct 06 '22 23:10

Ed Guiness


CodeMaid has a setting that automatically removes empty lines (when you save the file, I think) according to some configurable rules. I think it makes the files quite neat.

like image 37
Fredrik Mörk Avatar answered Oct 07 '22 01:10

Fredrik Mörk