[英]How to format file in Visual Studio Code (hotkeys)?
How to format file |如何格式化文件 | project folder |项目文件夹 | all project files (using hot keys AND using menu) in Visual Studio Code? Visual Studio Code 中的所有项目文件(使用热键和使用菜单)?
If you're on Windows use Shift + Alt + F to make your code "pretty". 如果您使用的是Windows,请使用Shift + Alt + F将代码设置为“漂亮”。
(This is similar to Ctrl + K + D in Visual Studio) (这类似于Visual Studio中的Ctrl + K + D )
You will have to do this for each individual file though. 但是,您必须为每个单独的文件执行此操作。 I don't know of a way to format all files at once. 我不知道一次格式化所有文件的方法。
试试这个热键
Ctrl + Shift + i
@Sergii @Sergii
Your question looks like you are looking for a way to format your entire code in VSCode. 您的问题看起来像是在寻找一种在VSCode中格式化整个代码的方法。 If this is the case, a VSCode extension like Prettier should meet the three requirements you've listed (file | project folder | all project files). 如果是这种情况,像Prettier这样的VSCode扩展应满足您列出的三个要求(文件|项目文件夹|所有项目文件)。 Bear in mind though that formatting all project files is a bit unclear and you probably want to be specific about formatting all *.ts or all *.js files etc. 请记住,格式化所有项目文件有点不清楚,您可能想要具体格式化所有* .ts或所有* .js文件等。
The below may be of help to you: 以下内容可能对您有所帮助:
The one I found most useful is adding it as a git pre-commit hook for staged files. 我发现最有用的一个是将它添加为阶段文件的git pre-commit钩子。
I hope above points you in the right direction. 我希望上面指出你正确的方向。
SOJ SOJ
In case you are not able to format your code with any of these commands it's maybe because you did not set up your formatter configuration如果您无法使用这些命令中的任何一个来格式化您的代码,那可能是因为您没有设置格式化程序配置
I recommend you to use Prettier (install from Extensions)我建议您使用 Prettier(从扩展安装)
prettier: Create Configuration File
搜索prettier: Create Configuration File
+1. +1。 also you are able to set your environment to automatically format your file at save.您还可以将环境设置为在保存时自动格式化文件。
You can do it writing this line in settings.json:你可以在 settings.json 中写下这一行:
"editor.formatOnSave": true
Hint: Access it using the command palette again and writing settings.json, and select提示:再次使用命令面板访问它并写入 settings.json 和 select
Preference: Open Settings (JSON)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.