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

孤街浪徒 提交于 2019-12-30 18:24:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!