Reputation: 21357
What is the shortcut to comment out multiple lines with Python Tools for Visual Studio?
Upvotes: 18
Views: 56517
Reputation: 21
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/or Edit.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.
Upvotes: 2
Reputation: 301037
CTRL+K then CTRL+C adds the #
in VS for selected lines.
CTRL+K then CTRL+U removes the #
in VS for selected lines.
Upvotes: 38
Reputation: 19
If you want to comment out any line in Python (when using Visual Code) then the shortcut is:
Ctrl + / (Ctrl button plus forward slash)
Upvotes: 1
Reputation: 17
All you need to do is select the block of code and type Ctrl+1.
Upvotes: 0
Reputation: 11
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.
Upvotes: 1
Reputation: 362
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:
Upvotes: 5