What is the shortcut to comment out multiple lines with Python Tools for Visual Studio?
CTRL+K then CTRL+C adds the #
in VS for selected lines.
CTRL+K then CTRL+U removes the #
in VS for selected lines.
ctrl+k
+ ctrl+c
to ctrl + shift + /
? –
Nonparous 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:
On python the only way is """ ... """
, practically just a string.
You need to reassign the shortcut key of the:
Edit.CommentSelection
and Edit.UncommentSelection
functions.
This is done by:
Open Options (Menu: Tools > Options...)
Choose Environment > Keyboard
In the Show commands containing type:
Edit.CommentSelection
and/orEdit.UncommentSelection
Now choose the shortcut key you want and press Assign.
Note: Edit.ToggleLineComment
and Edit.ToggleBlockComment
are not working when editing Python in Visual Studio 2022.
If you want to comment out any line in Python (when using Visual Code) then the shortcut is:
Ctrl + / (Ctrl button plus forward slash)
The easiest way to achieve this is to highlight all the previous written code that you wish to comment out, then press Ctrl+K and then Ctrl+C.
You will not experience any bugs or altered code during the process.
All you need to do is select the block of code and type Ctrl+1.
© 2022 - 2025 — McMap. All rights reserved.