简体   繁体   中英

Is there a shortcut to comment multiple lines in python using VS Code?

Instead of indivually typing out a hash tag in front of each line, is there a way to select a block of code and comment/uncomment everything by only pressing a couple shortcut keys?

Select all of the lines and do one of the following:

  • Windows: Ctrl + /
  • Mac: Cmd + /

All shortcuts:

All you need to do is select that code block with your mouse, then press the following key combination:

Ctrl + K then press Ctrl + C if you're using Windows
Command + K then press Command + C if you're on a Mac

You can also use:

Ctrl + / to comment and uncomment lines of Python code on Windows.
Command + / to comment and uncomment multiple lines of Python code on Mac.

I think the answers above all ignore a key piece of information the OP asked: multiple lines .

  1. Use shortcuts "Alt + left click" (Select multiple lines, do not need the beginning or end of the line, any position in the line can be OK) to select all the lines you want to comment.
  2. Use shortcuts "Ctrl+/" on windows or "Command + /" on MacOS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM