![](/img/trans.png)
[英]Regex match comments (single-line or multiple-line) and match everything else (C#)
[英]Visual Studio 2019: Insert multiple C++ style single-line comments
使用 Visual Studio 2019 社區 (v16.6.1)。 編輯C/C++/C#代碼時,select幾行代碼:
int countLines = 0;
if (!editingDocument)
countLines = GetDocumentLines();
現在觸發Edit.ToggleBlockComment
( Ctrl+Shift+/
) 或Edit.ToggleLineComment
( Ctrl+K, Ctrl+/
)。 在這兩種情況下,都會應用“C 風格”注釋:
/*int countLines = 0;
if (!editingDocument)
countLines = GetDocumentLines();*/
這沒關系,但我實際上想要 C++ 樣式,單行注釋:
// int countLines = 0;
// if (!editingDocument)
// countLines = GetDocumentLines();
這可能嗎? 理想的是使用“C 風格”的Edit.ToggleBlockComment
和使用“C++ 風格”的Edit.ToggleLineComment
。
多虧了其中一條評論,我可以確認當所選塊內至少有一條評論時,VS 足夠聰明,可以對整個塊使用 C++ 單行注釋。 雖然這不能回答問題,但目前它是一個有用的解決方法。
您可以在編輯器中通過Shift + Alt + Up/Down arrow
選擇文本列,然后只需鍵入//
你可以得到以下...
單擊一行中的任意位置,然后切換“//”注釋
Select 多行,並切換“//”注釋
保留以前評論過的小節
使用單個組合鍵,例如Ctrl-/
通過在鍵盤編輯器中將命令Edit.ToggleLineComment
設置為Ctrl-/
。
這與 Eclipse、IntelliJ 和 Android Studio 的功能相同。 一旦你把它拿到你的手指上,其他任何東西都是笨拙的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.