Is there any keyboard shortcut to remove empty lines开发者_C百科 in C# code files (.cs)?
Similar to Ctrl + K , D which formats the whole .cs file.
Or is there a workaround?
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+
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.
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.
I don't think there is any. You can use a separate refactoring add-in to automate this, such as ReSharper.
精彩评论