How to comment multiple lines with space or indent

ぐ巨炮叔叔 提交于 2019-12-03 04:13:43

问题


In Visual Studio 2010, I have multiple lines of text to be commented:

A
B
C

Using Ctr+E+C to comment out multiple lines, I get

//A
//B
//C

I would like to have a space (or indent) between // and A, hence // A instead of //A.

However, after I group tab a block of text and indent it, Ctr+E+C no longer comments out the selected text.

How to group comment and get the following:

// A
// B
// C

回答1:


One way to do it would be:

  1. Select the text, Press Cntl + K, C to comment (Ctr+E+C )
  2. Move the cursor to the first line after the delimiter // and before the Code text.
  3. Press Alt + Shift and use arrow keys to make selection. (Remember to make line selection(using down, up arrow keys), not the text selection - See Box Selection and Multi line editing)
  4. Once the selection is done, press space bar to enter a single space.

Notice the vertical blue line in the below image( that will appear once the selection is made, then you can insert any number of characters in between them)

I couldn't find a direct way to do that. The interesting thing is that it is mentioned in the C# Coding Conventions (C# Programming Guide) under Commenting Conventions.

Insert one space between the comment delimiter (//) and the comment text

But the default implementation of commenting in visual studio doesn't insert any space




回答2:


Pressing Ctrl+K+C or Ctrl+E+C After selecting the lines you want to comment will not give space after slashes. you can use multiline select to provide space as suggested by Habib

Perhaps, you can use /* before the lines you want to comment and after */ in that case you might not need to provide spaces.

/*
  First Line to Comment
  Second Line to Comment
  Third Line to Comment      
*/



回答3:


I was able to achieve the desired result by using Alt + Shift + up/down and then typing the desired comment characters and additional character.




回答4:


  • You can customize every short cut operation according to your habbit.

Just go to Tools > Options > Environment > Keyboard > Find the action you want to set key board short-cut and change according to keyboard habbit.




回答5:


Might just be for Visual Studio '15, if you right-click on source code, there's an option for insert comment

This puts summary tags around your comment section, but it does give the indentation that you want.



来源:https://stackoverflow.com/questions/14027598/how-to-comment-multiple-lines-with-space-or-indent

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