In Visual Studio 2010, I have multiple lines of text to be commented:
A
B
C
Using CTRL+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, CTRL+E+C no longer comments out the selected text.
How to group comment and get the following:
// A
// B
// C
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
*/
One way to do it would be:
Select the text, Press CTRL + K, C to comment (CTRL+E+C )
Move the cursor to the first line after the delimiter // and before the Code text.
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)
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
I was able to achieve the desired result by using Alt + Shift + up/down and then typing the desired comment characters and additional character.
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.
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.
Related
Is there a way (or tool) to stop Visual Studio text editor (2015 or 2017) from auto moving the comment lines when pressing Ctrl+K,D or relevant key stroke (Ctrl+E,D - format entire document) ?
I would like my comments to stay at the position placed, regardless of the code position above or below.
For example, when writing a comment line starting say at col 80 as
code line
|-------- white space -------------------| //... comment ..
code line
so that it doesn't interfere with the code below or above, when pressing Ctrl+K,D the comment is shifted left to align with the surrounding code.
On the other hand, when a comment is placed following a code line, as below
|----code line ------|-- white space --| //.... 1st comment line ....
|-------white space ---------------------| //.... 2nd comment line....
an eventual 2nd comment line remains aligned with the above one, which indicates that the editor can adjust the position of comment lines based on certain criteria
Edit: I should clarify that I would like to preserve the rest of the functionality of Ctrl+K,D
How can I Enable in VS8-10 the border/line that surround the codeblock where the cursor is? I have looked hard after this I kinda have to give up now. I have googled everything like: border, line, hightlight schope, and surround.
I know it's possible, I have used it before, but can't remember where to enable it.
e.g.:
if
{
if(foo)
{
________________________________________________________________
I var s; <cursor here> // border around this and the next line I
I var t; // border around this line too I
________________________________________________________________
}
}
Download "Ident Lines" in the Visual Studio Gallery or download Resharper.
For Resharper:
Click "RESHARPER" in the toolbar
Click "Options..."
Select "Environment > Editor > Editor Appearance"
Chech "Highlight matching delimiters when caret is"
Check "at both sides"
Check "outline"
In this case, I selected the first brace after MsgBox_MouseDown.
In ReSharper Options / Environment / Editor / Editor Appearance
Enable Highlight matching delimiters when caret is and set Highlight with option to outline.
You can do a rectangular selection by holding the ALT key down while dragging the mouse over a block of text.
May be it was the DevExpress CodeRush plugin you had seen previously, I have not used it myself but this question may help.
In the Visual Studio 2010 SDK there is SnapshotSpans and VirtualSnapshotSpans. According to MSDN, the difference is the Virtual Span has Virtual Spaces, the other does not.
What exactly is a Virtual Space?
For reference:
http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.text.virtualsnapshotspan.aspx
You can find an explanation here:
http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.text.virtualsnapshotpoint%28v=vs.100%29.aspx
Virtual spaces are "extra" spaces at the end of a line that do not add
to the length of the line. You can enable or disable virtual spaces in
Visual Studio. When virtual spaces are disabled, pressing on the right
arrow key at the end of a line causes the caret to move to the
beginning of the next line. When virtual spaces are enabled, pressing
on the right arrow key at the end of a line causes the caret to move
forward on the same line.
Even if the option “Enable virtual Space” under Tools -> Options -> Text Editor -> All Languages -> General is disabled, virtual spaces can be inserted when writing indented text or code.
If you type enter at the end of an indented line, Visual Studio adds virtual spaces at the beginning of the new line. These spaces are "virtual" since they have not been typed by the user and will not be saved in the file unless you enter something after the virtual spaces.
This affects the position of the caret:
After pressing enter at the end of an indented line the "BufferPosition"- and "VirtualBufferPosition"-properties of CaretPosition will be different.
BufferPosition points to column 0 in the new line and VirtualBufferPosition points to the position where the caret is visually rendered.
Accused to be not detailed enough, now I'll try to be detailed and descriptive as possible.
So, I have web application with textbox. Next to it I made label for preview, so when I click Submit, it sends text to remote application, when I press preview, it sends text to label for preview.
Remote application have specific text formatting, so When I type A text becomes red, B, text becomes green, and so on. When I wan't to change color, I type this sign for new color, I can't close color (like in HTML).
For new line, I also have a sign, it's #r
I also have sign for double width.
Main problem is to do following things:
Count characters and spaces, and break line on last space before 30th sign (replace space with #r (new row sign), so space wouldn't be taken to next row).
None of the #x(x is some letter) should be counted, as they just do text formatting.
While counting characters, when it comes to %Y (sign for double letter's width), it should count double those letters and spaces until it comes to #Z or #W, where normal letters with starts again, and from that point, count again one by one letter.
If anything is not clear enough, please ask.
You can access individual characters in a string that you get from the TextBox, and iterate over them:
StringBuilder newString = new StringBuilder();
for (int index = 0; index < textBox.Text.Length; index++)
{
char myChar = textBox.Text[index];
... apply your logic as need one char at a time...
... you might need extra variables outside of the loop to
... keep track of your last space before 30th character, etc.
newString.Append(...);
}
string result = newString.ToString();
Is there any keyboard shortcuts for commented a part of the line? when we want all the line will be comment use ctrl+C but when we need just some selection word between a line be commented what can do?
And is there any keyboard shortcut for select a word, assume your cursor is in the middle of the word and want select all the word (attention because the cursor is in the middle you can not use shift+left(or right)) is there any shortcut for this?
or Is there a keyboard combination to select an entire line?
Ctrl+W selects the current word in Visual Studio. If you are in the middle of a word and want to get to either side of it, Ctrl+Left/Right works great. So, for commenting a sequence of words to the right and if your cursor is in the middle of the first word, you can use Ctrl+Left, Ctrl+Shift+Right, Right, Right... to select all the words you want.
Select a word: Ctrl-W
(Un)comment one line out: Ctrl-K/C & Ctrl-K/U
Selecting a word is even better with Resharper: it allows you to extend your selection.
As for commenting out one word, no shortcuts that I know of.You could however create a macro to do that and hotkey it.
Not exactly an answer, but with CodeRush Express from DevExpress you can use the +/- from the numpad to increase and reduce selection. It offers very useful tools for refactoring.
To answer your question, without an extension this is not possible.