Key combination to delete blank lines in a C # code file

Is there a keyboard shortcut to delete blank lines in C # code files (.cs)?

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

Or is there a workaround?

+6
c # keyboard-shortcuts
source share
4 answers

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

\n\n 

and replace with

 \n 

using regular expressions (expand the "Search Options" section to include).

If you want to remove lines containing only spaces, you can try searching

 \n\s*\n+ 
+6
source share

CodeMaid has a parameter that automatically deletes empty lines (if you save the file, I think) in accordance with some custom rules. I think this makes the files pretty neat.

+4
source share

I do not think so. You can use a separate refactoring add-on for automation, for example ReSharper .

+1
source share

In the Visual Studio options in the Text Editor β†’ General section, there is the option "Apply the" Cut "and" Copy "commands to empty lines when there is no choice." If you check this, Ctrl + X will delete the empty line.

+1
source share

All Articles