简体   繁体   English

如何让 VSCode 正确自动缩进?

[英]How do I get VSCode to auto-indent this correctly?

I'm calling a function and I want the parameters to be on separate lines so I can comment them, like this:我正在调用一个函数,我希望参数在不同的行上,以便我可以对它们进行注释,如下所示:

doStuff(
    doItWell.quality,         // quality setting
    doItFast * 100,           // speed setting
    doItCheap.checkbox.value  //price setting
);
alert("done");

but VSCode auto-indent always does this:但 VSCode 自动缩进总是这样做:

doStuff(
    doItWell.quality,         // quality setting
    doItFast * 100,           // speed setting
    doItCheap.checkbox.value  //price setting
    );
    alert("done");

Note the extra indent on the alert() line.注意alert()行的额外缩进。

Prettier gets it, so when I type it in and it auto-formats it's all good, but as soon as I run VSCode's auto-indent I get the extra indentation.更漂亮了,所以当我输入它并自动格式化时,一切都很好,但是一旦我运行 VSCode 的自动缩进,我就会得到额外的缩进。

Prettier gets it, so when I type it in and it auto-formats it's all good, but as soon as I run VSCode's auto-indent I get the extra indentation.更漂亮了,所以当我输入它并自动格式化时,一切都很好,但是一旦我运行 VSCode 的自动缩进,我就会得到额外的缩进。

So you basically need to set Prettier as the default formatted.所以你基本上需要将 Prettier 设置为默认格式。 Go to the settings (by Ctrl + , ) and set "Editor: Default Formatter" to Prettier .转到设置(通过Ctrl + , )并将“编辑器:默认格式化程序”设置为Prettier

This will override your 'default' vscode formatter这将覆盖您的“默认”vscode 格式化程序

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

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