快捷鍵Shift + Alt + F
打開文件->首選項->設置
或者快捷鍵Ctrl + ,
搜索設置clang
如下圖
在上圖中 C_Cpp:Clang_format_style
下面的輸入框中輸入:
{
BasedOnStyle: Google,
UseTab: Never,
IndentWidth: 4,
TabWidth: 4,
AllowShortIfStatementsOnASingleLine: false,
ColumnLimit: 0
}
設置爲Google排版方式
Ubuntu 下修改格式化快捷鍵
Ubuntu 下代碼格式化快捷鍵默認爲:Shift+Ctrl+I
爲了保持和Windows一致,修改格式化快捷鍵
- 1 打開vscode命令行,快捷鍵:
Shift+Ctrl+P
- 2 在命令行輸入
Keyboard shortcuts
搜索出現:Preferences:Open Keyboard Shortcus
- 3 打開
Preferences:Open Keyboard Shortcus
,搜索format
- 4 雙擊 Format Document 輸入想要使用的快建鍵組合即可