如何在Visual Studio代碼(VSCode)中格式化代碼在Visual Studio中,Windows上的Ctrl+ K+ F和Ctrl+ K+ 相當于D在Visual Studio代碼編輯器中格式化或“美化”代碼?
3 回答

絕地無雙
TA貢獻1946條經驗 獲得超4個贊
Visual Studio Code中的代碼格式通過以下快捷方式提供:
在Windows Shift+ Alt+上F
在Mac Shift+ Option+上F
在Ubuntu Ctrl+ Shift+上I
或者,您可以通過編輯器中使用Ctrl+ Shift+ P(或Mac上的Command+ Shift+ P)提供的搜索功能找到快捷方式以及其他快捷方式,然后搜索格式文檔。

HUX布斯
TA貢獻1876條經驗 獲得超6個贊
代碼格式快捷方式:
Windows上的Visual Studio代碼 - Shift+ Alt+F
MacOS上的Visual Studio代碼 - Shift+ Option+F
Ubuntu上的Visual Studio代碼 - Ctrl+ Shift+I
如果需要,您還可以使用首選項設置自定義此快捷方式。
保存文件時的代碼格式:
Visual Studio Code允許用戶自定義默認設置。
如果要在保存時自動格式化內容,請在Visual Studio Code的工作空間設置中添加以下代碼段。
菜單文件 → 首選項 → 工作區設置
{ // Controls if the editor should automatically format the line after typing "beautify.onSave": true, "editor.formatOnSave": true, // You can auto format any files based on the file extensions type. "beautify.JSfiles": [ "js", "json", "jsbeautifyrc", "jshintrc", "ts" ]}
注意:現在您可以自動格式化TypeScript文件。檢查我的更新。
添加回答
舉報
0/150
提交
取消