What is the shortcut to comment out multiple lines with Python Tools for Visual Studio?
-
for me, you answered my question, install Python Tools for Visual Studio VS was highlighting first class symbols but that's about it, strangely only barks when using the normal hotkeys, without the tools, maybe this is the intention because it works for things like JSON and XML... thanks for the slight manipulation MS – fartwhif Jul 29 '20 at 01:38
8 Answers
CTRL+K then CTRL+C adds the #
in VS for selected lines.
CTRL+K then CTRL+U removes the #
in VS for selected lines.

- 2,305
- 3
- 21
- 21

- 290,304
- 63
- 469
- 417
-
1It is done with the Edit > Advanced > Comment Selection command. By opening the Edit > Advanced menu you can see that shortcut is. – Johan Råde Jun 05 '11 at 08:58
-
Hey @manojlds could you also include removing multi-line comments please? would be really helpful. – Jumabek Alikhanov May 17 '17 at 02:42
-
is there a way to remap ``ctrl+k`` + ``ctrl+c`` to ``ctrl + shift + /``? – Yannic Hamann Jul 05 '19 at 03:14
To make the comment of a block, it is a sequence of keys: Ctrl-K + Ctrl+C and to un-comment Ctrl-K + Ctrl-U.
Here are some other very useful keys for Python:

- 1
- 1

- 312
- 2
- 6
On python the only way is """ ... """
, practically just a string.

- 161,544
- 178
- 535
- 806
-
3You misunderstand the question. Most Python editors provide a simple mechanism for adding # to multiple lines at once. I'm asking if Python Tools for Visual Studio provides such a mechanism. – Johan Råde May 30 '11 at 06:52
-
1Also, this is not a comment. If it comes right after the beginning of a module/class/function it is a docstring, but not a comment. – Björn Pollex May 30 '11 at 06:58
All you need to do is select the block of code and type ctrl+1. You should be all set!

- 21
- 1
If you want to comment out any line in python (when using visual code) then the shortcut is: Ctrl + / (control button plus forward slash)

- 9
- 2
-
1The question asks about Visual Studio and is tagged accordingly. The question and the tag are quite clear that this is not about visual code. Why do you answer with a solution for visual code? – Yunnosch Aug 11 '21 at 05:35
The easiest way to achieve this is to highlight all the previous written code you wish to comment out, then control KC. You will not experience any bugs or altered code during the process. Sometimes Other methods just don't work.

- 1
- 2
-
Keep in mind this process is the most efficient way with some high-light delay, depending on the system. – Kevin Cook Aug 11 '21 at 05:34
-
1Which is true for all hot key approaches, which in turn the question asks specifically about. This does not put your answer apart from existing ones. Nevertheless, if you wish to add info to any of your posts, doing so by [edit]ing the post is better than to explain down here in the comments, which are at risk of being deleted at some point. – Yunnosch Aug 11 '21 at 05:37
-
@Yunnosch It states that bugs and code will not be altered using this process – Kevin Cook Aug 11 '21 at 05:37
-
-
Which is probably why the question specifically asks for a hot key for longer sections of code.... But fine, if you think that is the addtional insight thanks for hunoring me and explaining. – Yunnosch Aug 11 '21 at 05:39
-
@Yunnosch That is true thanks for the recommendation, I will add more insight to my original post instead of making comments. – Kevin Cook Aug 11 '21 at 05:39
-
@Yunnosch I will take the tour and read how to answer, looks like I have a lot left to learn. Thanks for the links. – Kevin Cook Aug 11 '21 at 05:42
-
True, but not a problem. Everybody learns. Don't you think that a higher reputation protects me from learning new things here. ;-) Nice that you take feedback so professionally. – Yunnosch Aug 11 '21 at 05:46
-
Yes, I noticed these things happening over time, some times the many changes prevented me from excelling in my niche, but with patience and persistence I've decided to move on from it and learn breadth first, one step at a time. I think a higher reputation is necessary and will come in time with the right ethic. Thanks again. I try. – Kevin Cook Aug 11 '21 at 19:02
instead you need to reassign your shortcut key of the Edit.CommentSelection function.

- 1
-
1Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 10 '23 at 16:11