I'm using visual studio 2010 , (with resharper installed if it helps) :
is there any shortcut of commenting a code via /* lalala */ and not via //lalala ?
I already know that CTRL K C comment a code but it comments it with //
Is there anyway of commenting a code via /**/ ?
There is ReSharper | Edit | Comment with block comment which makes exactly what you need.
Default shortcut for this - Ctrl+Shift+/
If you would like to uncomment it, put the caret on any place in the comment and hit Ctrl+Shift+/ once again. The same behavior is available for ReSharper | Edit | Comment with line comment (Ctrl+Alt+/) as well.
If you only select lalala and then hit CTRL K + C, it will uncomment lalala with /* */ (for example when lalala is a parameter in a function, just double click it and hit CTRL K+C.
Found it in resharper :
you can add :
Related
Sometimes I have the need to try: A code example or a variant of it.
This is necessary to test a new functionality or to test its implementation or performance.
The code can be very long.
So I need some way to quickly comment on the code with
/*
* mi código
* …
* /
O con:
//
// mi código
// …
//
When the code is very long, it is cumbersome to do: Select all the code you do not want to run and discuss, Write or insert the code you want to try, Do tests or whatever...
Now...
Select and comment on the new block of code.
Search and select the previous code, and Uncomment.
Do tests or whatever...
And so I need to do it many times since I'm recycling, as I have been thirty years since I program almost nothing.
Is There any way or trick to do it quickly?
If you're in vs code just enter ctrl + /. For VS studio 2017 ctrl + k + u.
If you are using visual studio as your IDE you can use the following:
Ctrl+K+C to commment and Ctrl+K+U to uncomment.
If using pycharm or VS Code:
Use Cntrl+/ to comment and uncomment.
In Visual Studio 2019 Preview
Comment : Ctrl + k and Ctrl + c
Uncomment : Ctrl + k and Ctrl + u
You can select all lines in the code cell with Ctrl+A (Windows/Linux) or Cmd+A (Mac)
Then press Ctrl+/ (Windows/Linux) or Cmd+/ (Mac) to uncomment
Press / again to comment
Trick:
When We have a very long code and need to comment and uncomment quickly:
ADD at the beginning of the BLOCK:
/*//TODO: Comment or uncomment this block.
Remove an inclined bar at the beginning of the line to uncomment.
Add an inclined bar at the beginning of the line to comment. '
And add at the end of the block
/*/
The tag TODO: It shows you in tasks the message,
so you can locate it quickly.
In Addition the commented code can collapse in the [+] when it is commented.
Commented Code:
[+]/*//TODO: Add a "/" at startup to uncomment.
This block does something.
...
Code 100000.0 lines.
...
/*/
Uncommented Code:
//*//TODO: Remove a "/" at startup to comment.
This block does something.
[+] ...
Code 100000.0 lines.
...
/*/
I Didn't know how to tell everybody, like I do.
I Hope it's useful.
Problem:
When I toggle a comment in Pydev it adds a space, inconveniencing me to manually correct this indentation. This was not an issue with earlier versions of Eclipse/Pydev. This problem occurs if I use the comment toggle key (ctrl + /) alone, or if I use it in combination with the uncomment key (ctrl + \).
System Versions:
Eclipse Juno (Version: 4.2.2), Pydev 2.7.3
Examples:
a = 4
# a = 4
a = 4
In line 2 I comment that code (ctrl + /). Line 3 I uncomment (ctrl + /). Notice there is a lingering space before the a in line 3.
Redoing this example with the same version of eclipse but using java no spaces are added:
a = 4
//a = 4
a = 4
So, I think this is a pydev issue.
Research:
As I said before, this is not an issue with my Eclipse Indigo / Pydev 2.5 install. Spaces are neither added nor subtracted when toggling comments (ctrl + /).
This appeared on stackoverflow before as an issue in java. The fix provided there had no effect for me (it doesn't matter if I use tabs or spaces):
Eclipse "Toggle Comment" Shortcut Indents on New Projects
This issue has also been reported on pydev source forge:
http://sourceforge.net/p/pydev/bugs/1547/
Work Around:
This is a solution for me, but isn't a true solution to the problem at hand. As suggested in the link above, do the following:
go to (in Preferences): Pydev | Editor | Code Style | Code Formatter
for the "Spaces in comment start?" combobox select "Don't change manual formatting".
Again, this solves my problem but doesn't solve the true problem at hand for someone who would like there to be spaces separating their comment from the comment symbol.
Also, because the default install preference is set to: "At least one space", this isn't an issue you would intuitively know how to fix upon just installing pydev for the first time.
This may not be exactly what you're seeking, but Eclipse (Oxygen with CDT, PyDev)
seems to preserve spacing spacing pretty well when using block comments. (under Source menu)
Add Comment Block Ctrl + 4
Add Single Comment Block Ctrl+Shift+4
Remove Comment Block Ctrl + 5
Ctrl + 4 works nicely in a .py file for Eclipse Photon with PyDev.
For any files which are not .py it may be useful after selecting text to use:
Edit -> Toggle Block Selection
..to manually put your '# ' simultaneously on all the lines where you want it, like in Sublime.
I couldn't find such feature in VS's shortcut list. Is there anyway?
If you want to copy a line, simply place cursor somewhere in that line and hit CTRL+C
To cut an entire line CTRL+X
#Sean found what I was looking for:
To disable this default behavior remove the checkmark (or check to re-enable)
Apply cut or copy commands to blank lines when there is no selection
Accessed from the menu bar: Tools | Options | Text Editor | All languages
You can also enter copy into the options search box for quicker access
[Tested in VS2008, 2010, 2017]
Clicking the line 3 times does the trick
If you have ReSharper you could use
Ctrl + W
- Extend Selection
Sidenote: You may have to use it multiple times depending on the context of your present text cursor position.
If you click once on the row number the entire row will be selected.
If you want to select a line or lines you can use the combination of ctrl + E then U. This combination also works for uncommenting a complete line or lines. This combination looks somewhat strange to work with, but it will get habituated very soon :)
You can also use Ctrl + X to cut an entire line. Similarly, you can use Ctrl + C to copy an entire line.
As long as you don't have anything selected, these commands will work on the entire line.
Clicking anywhere on the line and (CRTL + C) will copy entire line.
Clicking three time in quick succession also selects entire line.
There is a simple way of doing it, simple use Home or End button to reach the start or end of line, and then use home + shift or end + Shift depending on where your cursor is. Hope it helps.
Use the following:
Shift + End If cursor is at beginning of line.
or
Shift + Home If cursor is at the end of the line.
Alternatively, if you use resharper, you can also use the following
Ctrl + w while the cursor is positioned on the line you want to select
This won't solve the problem for Visual Studio, but if you're using Visual Studio Code you can use CTRL+L to select the line your cursor is currently on.
(If you're using Visual Studio, this will cut the line you're currently on—which may also be useful, but wasn't the question.)
Other answers require either using a mouse or hitting more than one combination.
So I've created a macro for those who want a VSCode-like Ctrl+L behaviour. It can select multiple lines, and that's useful for moving blocks of code.
To use it, install Visual Commander extension for macros: https://marketplace.visualstudio.com/items?itemName=SergeyVlasov.VisualCommander
Then create a new command, select C# as a language and paste this code:
using EnvDTE;
using EnvDTE80;
public class C : VisualCommanderExt.ICommand
{
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
var ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
if (!ts.ActivePoint.AtStartOfLine)
ts.StartOfLine();
ts.LineDown(true, 1);
}
}
Now you can assign a desired shortcut in preferences:
Tested in VS 2022.
You can use CTRL + U . This shortcut is use also for uncomment.
You can change the shortcut on this feature. Go to Tools->Options->Environment->Keyboard->Edit.UncommentSelection and assign CTRL+W (same as Resharper) or you can use what shortcut do you want.
If you want to select full row Ctrl E + U
Just click in the left margin.
If you click in the margin just left of the Outline expansions [+][-]
it will select the row.
You can also just click and drag to select multiple lines.
Necvetanov eluded to this in his answer above about clicking on the line number.
This is right...but it just happens that the line number is in the margin.
Here is a whole list of the keyboard shortcuts Default keyboard shortcuts in Visual Studio
a work around for this:
ctrl+d = duplicate line
ctrl+l = copy line
ctrl+v = paste copied text
You can enter, home then shift + end as well. What it will do is take you to the beginning of line then select the whole line till end. Or alternatively first enter end then shift + home
You can set a bind to the Edit.ExpandSelection command:
In the options. Click the shortcut until it selects the whole line.
The screenshot above is from the Edit > Advanced menu in Visual Studio 2022. I set this Alt+E, E shortcut myself and I don't remember if it's originally set to something or not.
Simply by clicking on the line number that's being shown on the left in vs-code. just a single click and a line will get selected.
In Mac, it is ⌘+L.
But if you have some specific conflicting keybindings, this won't work. In my case the VSCode Live Server extension auto registered a couple of bindings for these keys. I removed them and it worked.
I assigned a shortcut key to the following functionality. I press the shortcut until it selects the whole current line:
Edit.SubwordExpandSelection
How can I automatically indent source code in Visual Studio 2010?
I have used Ctrl + K, Ctrl + F, but it does not work; is there any other way/plugin to do this?
Ctrl+E, D - Format whole doc
Ctrl+K, Ctrl+F - Format selection
Also available in the menu via Edit|Advanced.
Thomas
Edit-
Ctrl+K, Ctrl+D - Format whole doc in VS 2010
In 2010 it is Ctrl+k, Ctrl+d. See image below.
In Visual Studio 2010
Ctrl +k +d indent the complete page.
Ctrl +k +f indent the selected Code.
For more help visit : http://msdn.microsoft.com/en-us/library/da5kh0wa.aspx
every thing is there.
In 2010 it is ctrl +k +d for indentation
Also, there's the handy little "increase indent" and "decrease indent" buttons. If you highlight a block of code and click those buttons the entire block will indent.
I have tried both ways, and from the Edit|Advanced menu, and they are not doing anything to my source code. Other options like line indent are working. What could be wrong? – Chucky Jul 12 '13 at 11:06
Sometimes if it doesnt work, try to select a couple lines above and below or the whole block of code (whole function, whole cycle, whole switch, etc.), so that it knows how to indent.
Like for example if you copy/paste something into a case statement of a switch and it has wrong indentation, you need to select the text + the line with the case statement above to get it to work.
It may be worth noting that auto-indent does not work if there are syntax errors in the document. Get rid of the red squigglies, and THEN try CTRL+K, CTRL+D, whatever...
Is there a way to comment various lines at the same time in Xcode IDE? Selecting which lines to comment, then clicking somewhere et voilá.. the /* ... */ characters wrapping the code.
Thank you.
Command + Shift + 7
or
Command + /
This inserts // in front of every selected line.
Xcode Version 6.1
Shortcuts:
To Comment: Select the code to be comment, ⌘ + /
To uncomment: Select the code an press ⌘ + /
Also see taskbar Editor>Structure "(un)Comment Selection" as user 2137640 pointed out.
The answer is actually very simple if you want to comment a continuous sequence of lines. Select the consecutive lines, then simply press ⌘ /.
I have no idea how to comment multiple non-consecutive lines. Maybe somebody else can help with this, if it is even possible (I doubt it.)
I've been using the Command + Shift + 7 for years, but now in Xcode 13.1 it just started to open the help menu instead of commenting the selected block.
Apparently the new command for commenting a selection of code is:
Command + Shift + ?
Edit:
Another solution is to deselect "Show Help menu" in settings > keyboard > App Shortcuts
There is such a function in the menu. Try: Edit->Insert Text Macro->C->Comment Section.
It will create a (multi-line) comment around the currently selected text.
However, using the menu is probably often slower than manually inserting the comments. But, you can also bind a key to the menu item via the preferences key binding settings.
For single line Comment use ⌘+/
For multiline Comment you need to install CComent plugin
to install plugin manager use alcatraz
new Xcode 14:
Keys: Command + '
in Xcode 7.x
Shortcuts:
To Comment: Select the code to be comment, ⌘ + /
To uncomment: Select the code an press ⌘ + /
Got it! You have to un-indent the lines so the comments are the first character on the line, not a tab or whitespace - then pressing CMD+/ works. Just tried it in XCode 5.1.1, works like a charm.
This worked !
Higlight the desired lines then press Command + /
The same rule goes for uncommenting.
For xcode 8 ->
sudo /usr/libexec/xpccachectl
restart your computer
In Turkish keyboard cmd + *
You can use uncomment and multiline comment.