Visual studio code vscode在注释行时保留缩进
在vscode(或我为此尝试的大多数其他编辑器)中,当我有这样一块代码时:Visual studio code vscode在注释行时保留缩进,visual-studio-code,comments,indentation,vscode-settings,Visual Studio Code,Comments,Indentation,Vscode Settings,在vscode(或我为此尝试的大多数其他编辑器)中,当我有这样一块代码时: function() { if(test1) { doThis(); andThenDoThat(); } } 我尝试注释掉行和endothat(),例如按Ctrl+/,我将得到以下结果: function() { if(test1) { doThis(); // andThenDoThat(); } } 我想得到的是:
function() {
if(test1) {
doThis();
andThenDoThat();
}
}
我尝试注释掉行和endothat()
,例如按Ctrl+/,我将得到以下结果:
function() {
if(test1) {
doThis();
// andThenDoThat();
}
}
我想得到的是:
function() {
if(test1) {
doThis();
// andThenDoThat();
}
}
换句话说,我希望注释保留代码的原始缩进,而是从行的开头开始,因为这不是一般的人类可读注释,而是代码,我认为保留缩进时可读性要高得多
这可能吗?也许有一个插件?我认为这是可行的,从 你需要分机 在您的设置中:
"multiCommand.commands": [
{
"command": "multiCommand.insertCommentColumn0",
"sequence": [
"cursorLineStart",
{
"command": "type",
"args": {
"text": "//"
}
},
"deleteRight",
"deleteRight"
]
},
{
"command": "multiCommand.AddCommentColumn0MultipleLines",
"sequence": [
"editor.action.insertCursorAtEndOfEachLineSelected",
"cursorLineStart",
{
"command": "type",
"args": {
"text": "//"
}
},
"deleteRight",
"deleteRight",
"removeSecondaryCursors"
]
},
{
"command": "multiCommand.removeCommentsSingleLine",
"sequence": [
"editor.action.removeCommentLine",
"cursorLineStart",
{
"command": "type",
"args": {
"text": " "
}
},
"removeSecondaryCursors"
]
},
{
"command": "multiCommand.removeCommentsMultipleLines",
"sequence": [
"editor.action.insertCursorAtEndOfEachLineSelected",
"cursorLineStart",
"editor.action.removeCommentLine",
{
"command": "type",
"args": {
"text": " "
}
},
"removeSecondaryCursors"
]
}
]
在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 macro multiCommand.removeCommentsSingleLine when
// uncommenting a single line
"key": "ctrl+shift+/",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.removeCommentsSingleLine" },
"when": "!editorHasSelection && editorTextFocus && !editorReadonly && resourceExtname =~ /\\.(js$|php)/"
},
{ // call the macro multiCommand.removeCommentsMultipleLines when
// uncommenting multiple lines
"key": "ctrl+shift+/",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.removeCommentsMultipleLines" },
"when": "editorHasSelection && editorTextFocus && !editorReadonly && resourceExtname =~ /\\.(js$|php)/"
},
与另一个链接答案中的警告相同,请阅读。我只针对js/php文件做了上述操作,显然它不适用于html/css/scss等具有不同于javascript注释标记的文件
Ctrl+Shift+/删除注释(您可以选择您喜欢的任何键绑定)。按Ctrl+/键进行注释
谢谢,我会试试看的!:)的确是这样的话,再次感谢!但是我不得不修改keybinding中的正则表达式,以包含我现在主要使用的TypeScript:
“when”:“editorTextFocus&&!editorReadonly&&resourceExtname=~/\\(ts | js | php)$/”