简体   繁体   English

是否有使用 VS 代码在 python 中注释多行的快捷方式?

[英]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?不是在每行前面单独输入 hash 标签,有没有办法通过按几个快捷键来 select 代码块和注释/取消注释所有内容?

Select all of the lines and do one of the following: Select 所有行并执行以下操作之一:

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

All shortcuts:所有快捷方式:

All you need to do is select that code block with your mouse, then press the following key combination:您需要做的就是使用鼠标进行代码块 select,然后按以下组合键:

Ctrl + K then press Ctrl + C if you're using Windows Ctrl + K 然后按 Ctrl + C 如果您使用的是 Windows
Command + K then press Command + C if you're on a Mac Command + K 然后按 Command + C 如果您使用的是 Mac

You can also use:您还可以使用:

Ctrl + / to comment and uncomment lines of Python code on Windows. Ctrl + / 在 Windows 上注释和取消注释 Python 代码行。
Command + / to comment and uncomment multiple lines of Python code on Mac. Command + / 在 Mac 上注释和取消注释多行 Python 代码。

I think the answers above all ignore a key piece of information the OP asked: multiple lines .我认为最重要的答案忽略了OP询问的一个关键信息:多行

  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.使用快捷键“Alt+左键” (选择多行,不需要行首或行尾,行中任意position都可以)到select所有要注释的行。
  2. Use shortcuts "Ctrl+/" on windows or "Command + /" on MacOS在 windows 上使用快捷键“Ctrl+/”或在 MacOS 上使用“Command + /”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用快捷键 ctrl + # 在 Python 或 C++ 中使用 Vscode 注释多行代码? - How can I use the shortcut ctrl + # to comment multiple lines of code in Python or C++ using Vscode? 使用 Python Tools for Visual Studio 注释掉多行的快捷方式 - Shortcut to comment out multiple lines with Python Tools for Visual Studio 在 VS Studio Code 中是否有将多行代码格式化为一行的快捷方式 - Is there a shortcut to format multiple lines of code into one line in VS Studio Code 自动保存在 VS 代码中的 Python 中的注释和函数头之间添加两个空行 - Auto save adds two empty lines between comment and function header in Python in VS code 如何在 Visual Studio 中注释多行代码 - How to comment multiple lines of code in visual studios 使用python计算python文件中的注释行和注释块的数量 - Using python to count number of comment lines and comment blocks in python file 在 vs 代码 python 调试控制台中运行循环/多行 - Running a loop/multiple lines in vs code python debug console 当前在 VS Code 中运行 Python 的快捷方式 - Current shortcut to run Python in VS Code 使用python注释文本文件中的某些行 - Comment some lines in a text file using python 在 netbeans python 中切换评论快捷方式? - Toggle comment shortcut in netbeans python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM