5 回答

TA貢獻1798條經驗 獲得超7個贊
您需要選擇默認格式化程序。
按
Ctrl+Shift+P
(Win) 或Cmd+Shift+P
(Mac)鍵入格式化文檔...
然后單擊Configure Default Formatter...并從列表中選擇它。

TA貢獻1871條經驗 獲得超13個贊
這可能是由于 vs code 中可用的格式工具存在沖突。為了解決這個
按
Ctrl+Shift+P
(windows) 或Cmd+Shift+P
(Mac)類型
Format Document With...
選擇
Configure default Formatter...
為以后的格式選擇一個選項。(如果你選擇的是 vs code 的內置格式工具,最好禁用/刪除其他代碼格式擴展)
選擇全部
Ctrl+A
(Windows) 或Cmd+A
(Mac),然后按Ctrl+K Ctrl+F
(windows) 或Cmd+K Cmd+F
來格式化文檔。

TA貢獻1829條經驗 獲得超6個贊
如果您在 Visual Studio Code 中使用更漂亮的擴展,請嘗試將其添加到 settings.json 文件中:
"editor.insertSpaces": false,
"editor.tabSize": 4,
"editor.detectIndentation": false,
"prettier.tabWidth": 4,
"prettier.useTabs": true // This made it finally work for me
好吧,如果您喜歡開發人員方式,Visual Studio Code 允許您為 tabSize 指定不同的文件類型。這是我的 settings.json 示例,默認有四個空格,JavaScript/JSON 有兩個空格:
{
// I want my default to be 4, but JavaScript/JSON to be 2
"editor.tabSize": 4,
"[javascript]": {
"editor.tabSize": 2
},
"[json]": {
"editor.tabSize": 2
},
// This one forces the tab to be **space**
"editor.insertSpaces": true
}
添加回答
舉報