Visual studio code 从列位置0开始对VSCode进行注释
在VSCode中,当我按下组合键ctrl+/时,VSCode将对所选行进行注释,以确保缩进完好无损。因此,如果一行代码从位置16开始,那么注释的双斜杠(即,Visual studio code 从列位置0开始对VSCode进行注释,visual-studio-code,comments,keyboard-shortcuts,vscode-settings,Visual Studio Code,Comments,Keyboard Shortcuts,Vscode Settings,在VSCode中,当我按下组合键ctrl+/时,VSCode将对所选行进行注释,以确保缩进完好无损。因此,如果一行代码从位置16开始,那么注释的双斜杠(即,/)将位于位置16,从而将代码稍微向右移动 我想设置它,这样当我按下ctrl+/时,注释双斜杠/将始终从列位置0开始。这可能吗 谢谢。这有点棘手,但请测试一下。您需要像这样的宏扩展 在keybindings.json中: { // disable ctrl+/ for js/php files only
/
)将位于位置16,从而将代码稍微向右移动
我想设置它,这样当我按下ctrl+/时,注释双斜杠/
将始终从列位置0开始。这可能吗
谢谢。这有点棘手,但请测试一下。您需要像这样的宏扩展 在keybindings.json中:
{ // disable ctrl+/ for js/php files only
"key": "ctrl+/",
"command": "-editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly && resourceExtname =~ /\\.(js$|php)/"
},
{ // call the macro multiCommand.insertCommentColumn0 when
// commenting a single line
"key": "ctrl+/",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.insertCommentColumn0" },
"when": "!editorHasSelection && editorTextFocus && !editorReadonly && resourceExtname =~ /\\.(js$|php)/"
},
{ // call the macro multiCommand.AddCommentColumn0MultipleLines when
// commenting more than one line
"key": "ctrl+/",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.AddCommentColumn0MultipleLines" },
"when": "editorHasSelection && editorTextFocus && !editorReadonly && resourceExtname =~ /\\.(js$|php)/"
},
{ // call the command editor.action.removeCommentLine when
// commenting a single or multiple line(s)
"key": "ctrl+shift+/",
"command": "editor.action.removeCommentLine",
"when": "!editorHasSelection && editorTextFocus && !editorReadonly && resourceExtname =~ /\\.(js$|php)/"
},
在settings.json中,宏:
"multiCommand.commands": [
{
"command": "multiCommand.insertCommentColumn0",
"sequence": [
"cursorLineStart",
{
"command": "type",
"args": {
"text": "// "
}
},
]
},
{
"command": "multiCommand.AddCommentColumn0MultipleLines",
"sequence": [
"editor.action.insertCursorAtEndOfEachLineSelected",
"cursorLineStart",
{
"command": "type",
"args": {
"text": "// "
}
},
"removeSecondaryCursors"
]
},
此
resourceExtname=~/\\(js$| php)/
将键绑定限制为.js
和.php
文件(而不是.json
文件)。如果希望键绑定应用于更多文件类型,则可以更改此设置
Ctrl+/在列位置0处应用注释字符,Ctrl+Shift+Ctrl删除注释字符
你可以把那些钥匙换成你想要的任何东西。注意,使用Ctrl+/-键绑定并不是(目前也不能)一个简单的切换,无法检测注释是否已经存在。您需要一个扩展来获得这种功能
此方法的一个缺点是,如果选择多行并对其进行注释,则会丢失多行选择(如演示中所示)。您希望使用哪种语言?@Mark-我更喜欢所有编辑器的通用解决方案。但是,我将其用于JavaScript和PHP@Greeso我很高兴我不是唯一一个看到这种评论好处的人!:)