Johan Råde
Johan Råde

Reputation: 21357

Shortcut to comment out multiple lines with Python Tools for Visual Studio

What is the shortcut to comment out multiple lines with Python Tools for Visual Studio?

Upvotes: 18

Views: 56517

Answers (7)

lulshet
lulshet

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.

Edit Comment Shortcut keys

Note: Edit.ToggleLineComment and Edit.ToggleBlockComment are not working when editing Python in Visual Studio 2022.

Upvotes: 2

manojlds
manojlds

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

Priya Kulkarni
Priya Kulkarni

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

Andre The Wildebeest
Andre The Wildebeest

Reputation: 17

All you need to do is select the block of code and type Ctrl+1.

Upvotes: 0

Kevin Cook
Kevin Cook

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

Pierre Ghislain
Pierre Ghislain

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:

Short Keys for Visual Studio 2015 - Python

Upvotes: 5

sorin
sorin

Reputation: 170310

On python the only way is """ ... """, practically just a string.

Upvotes: 2

Related Questions