问题
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?
回答1:
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+
回答2:
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.
回答3:
In the Visual Studio options, under Text Editor -> General, there's an option "Apply Cut and Copy commands to blank lines when there is no selection". If you check this, Ctrl + X will remove a blank line.
回答4:
I don't think there is any. You can use a separate refactoring add-in to automate this, such as ReSharper.
来源:https://stackoverflow.com/questions/4312816/keyboard-shortcut-to-remove-empty-lines-in-a-c-sharp-code-file