VS Code 的 3 個(gè)奇技淫巧
分享 3 個(gè) VS Code 使用技巧,選項(xiàng)雖然少,但真的很有幫助。看完本文請(qǐng)告訴我你的使用感受。
啟用原生括號(hào)成對(duì)著色
在我們編碼的時(shí)候,肯定會(huì)有函數(shù)嵌套或是其他一些邏輯判斷等層層嵌套,隨著代碼量的增加,你會(huì)不會(huì)感覺括號(hào)嵌套太多層而導(dǎo)致代碼難以閱讀?
如果你對(duì)類似問題困惑的話,VS Code 中安裝 Bracket Pair Colorizer 插件可以幫助你實(shí)現(xiàn)各個(gè)成對(duì)的括號(hào)都會(huì)以不同的顏色進(jìn)行區(qū)別,對(duì)于括號(hào)很多的代碼非常實(shí)用。不過會(huì)帶來性能問題。
現(xiàn)在有原生括號(hào)對(duì)著色功能,而且速度要快得多,大文件也可以快速渲染,可以拋棄Bracket Pair Colorizer插件了。
配置
- 確保移除 Bracket Pair Colorizer 擴(kuò)展。
- 更新 VS Code
- 打開 JSON 文件。添加以下內(nèi)容:
- "editor.bracketPairColorization.enabled": true
比如為 One Monokai 主題自定義的括號(hào)顏色:
- "workbench.colorCustomizations": {
- "editorBracketHighlight.foreground1": "#5bb3b3",
- "editorBracketHighlight.foreground2": "#fac863",
- "editorBracketHighlight.foreground3": "#f99157",
- "editorBracketHighlight.foreground4": "#ec5f67",
- "editorBracketHighlight.foreground5": "#bb80b3",
- "editorBracketHighlight.foreground6": "#98C379",
- }
啟用內(nèi)聯(lián)提示預(yù)覽自動(dòng)完成你的代碼
- "editor.suggest.preview": true,
排序代碼
- {
- "key": "shift+alt+s",
- "command": "editor.action.sortLinesAscending"
- }
使用macros運(yùn)行多個(gè)操作
因?yàn)檫@仍然不是原生功能,所以我正在使用macros擴(kuò)展。
- {
- "key": "shift+alt+f",
- "command": "macros.fixDocumentAndSort",
- "when": "editorHasDocumentFormattingProvider && editorTextFocus && !editorReadonly && !inCompositeEditor"
- }
- "macros": {
- "eslintFixAndFormatDocument": [
- "eslint.executeAutofix",
- "editor.action.formatDocument"
- ],
- },
在這個(gè)綁定中,VS Code 正在執(zhí)行兩個(gè)動(dòng)作
- 格式化文檔
- 修復(fù) eslint 問題。
OK,就這樣,希望你喜歡。