Visual Studio Code

1. 官方网站

官网:https://code.visualstudio.com/

2. 常用插件

2.1. Chinese (Simplified) Language Pack for VS Code

中文汉化包

2.2. Eclipse Keymap(弃用)

配置与eclipse差不多一致的快捷键

2.3. Vetur

配置vue文件语法高亮、智能感知、Emmet等。
注意:VSCode中使用vetur插件格式化vue文件时,js代码会被添加上分号且单引号会转变为双引号。设置vscode配置文件

  1. "vetur.format.defaultFormatter.js": "vscode-typescript"

2.4. vscode-icon 或 Material Icon Theme

让vscode资源目录加上图标(必备)

2.5. Path Intellisense

自动路劲补全,默认不带这个功能的(必备)

2.6. Path Autocomplete

地址补全插件

2.7. 推荐主题

One Monokai Theme
03-Visual-Studio-Code - 图1
One Dark Pro
03-Visual-Studio-Code - 图2
Atom One Dark Theme
03-Visual-Studio-Code - 图3
Eva Theme
03-Visual-Studio-Code - 图4
Material Palenight Theme
03-Visual-Studio-Code - 图5

2.8. eslint插件

03-Visual-Studio-Code - 图6
安装并配置完成 ESLint 后,继续回到 VSCode 进行扩展设置,依次点击 文件 > 首选项 > 设置 打开 VSCode 配置文件,添加如下配置

  1. "files.autoSave":"off",
  2. "eslint.validate": [
  3. "javascript",
  4. "javascriptreact",
  5. "html",
  6. { "language": "vue", "autoFix": true }
  7. ],
  8. "eslint.options": {
  9. "plugins": ["html"]
  10. }
  11. ]

这样每次保存的时候就可以根据根目录下.eslintrc.js配置的eslint规则来检查和做一些简单的fix。以下github上的开源后台项目vue-element-admin的作者常用的eslint配置(参考)

  1. module.exports = {
  2. root: true,
  3. parserOptions: {
  4. parser: 'babel-eslint',
  5. sourceType: 'module'
  6. },
  7. env: {
  8. browser: true,
  9. node: true,
  10. es6: true,
  11. },
  12. extends: ['plugin:vue/recommended', 'eslint:recommended'],
  13. // add your custom rules here
  14. //it is base on https://github.com/vuejs/eslint-config-vue
  15. rules: {
  16. "vue/max-attributes-per-line": [2, {
  17. "singleline": 10,
  18. "multiline": {
  19. "max": 1,
  20. "allowFirstLine": false
  21. }
  22. }],
  23. "vue/name-property-casing": ["error", "PascalCase"],
  24. 'accessor-pairs': 2,
  25. 'arrow-spacing': [2, {
  26. 'before': true,
  27. 'after': true
  28. }],
  29. 'block-spacing': [2, 'always'],
  30. 'brace-style': [2, '1tbs', {
  31. 'allowSingleLine': true
  32. }],
  33. 'camelcase': [0, {
  34. 'properties': 'always'
  35. }],
  36. 'comma-dangle': [2, 'never'],
  37. 'comma-spacing': [2, {
  38. 'before': false,
  39. 'after': true
  40. }],
  41. 'comma-style': [2, 'last'],
  42. 'constructor-super': 2,
  43. 'curly': [2, 'multi-line'],
  44. 'dot-location': [2, 'property'],
  45. 'eol-last': 2,
  46. 'eqeqeq': [2, 'allow-null'],
  47. 'generator-star-spacing': [2, {
  48. 'before': true,
  49. 'after': true
  50. }],
  51. 'handle-callback-err': [2, '^(err|error)$'],
  52. 'indent': [2, 2, {
  53. 'SwitchCase': 1
  54. }],
  55. 'jsx-quotes': [2, 'prefer-single'],
  56. 'key-spacing': [2, {
  57. 'beforeColon': false,
  58. 'afterColon': true
  59. }],
  60. 'keyword-spacing': [2, {
  61. 'before': true,
  62. 'after': true
  63. }],
  64. 'new-cap': [2, {
  65. 'newIsCap': true,
  66. 'capIsNew': false
  67. }],
  68. 'new-parens': 2,
  69. 'no-array-constructor': 2,
  70. 'no-caller': 2,
  71. 'no-console': 'off',
  72. 'no-class-assign': 2,
  73. 'no-cond-assign': 2,
  74. 'no-const-assign': 2,
  75. 'no-control-regex': 0,
  76. 'no-delete-var': 2,
  77. 'no-dupe-args': 2,
  78. 'no-dupe-class-members': 2,
  79. 'no-dupe-keys': 2,
  80. 'no-duplicate-case': 2,
  81. 'no-empty-character-class': 2,
  82. 'no-empty-pattern': 2,
  83. 'no-eval': 2,
  84. 'no-ex-assign': 2,
  85. 'no-extend-native': 2,
  86. 'no-extra-bind': 2,
  87. 'no-extra-boolean-cast': 2,
  88. 'no-extra-parens': [2, 'functions'],
  89. 'no-fallthrough': 2,
  90. 'no-floating-decimal': 2,
  91. 'no-func-assign': 2,
  92. 'no-implied-eval': 2,
  93. 'no-inner-declarations': [2, 'functions'],
  94. 'no-invalid-regexp': 2,
  95. 'no-irregular-whitespace': 2,
  96. 'no-iterator': 2,
  97. 'no-label-var': 2,
  98. 'no-labels': [2, {
  99. 'allowLoop': false,
  100. 'allowSwitch': false
  101. }],
  102. 'no-lone-blocks': 2,
  103. 'no-mixed-spaces-and-tabs': 2,
  104. 'no-multi-spaces': 2,
  105. 'no-multi-str': 2,
  106. 'no-multiple-empty-lines': [2, {
  107. 'max': 1
  108. }],
  109. 'no-native-reassign': 2,
  110. 'no-negated-in-lhs': 2,
  111. 'no-new-object': 2,
  112. 'no-new-require': 2,
  113. 'no-new-symbol': 2,
  114. 'no-new-wrappers': 2,
  115. 'no-obj-calls': 2,
  116. 'no-octal': 2,
  117. 'no-octal-escape': 2,
  118. 'no-path-concat': 2,
  119. 'no-proto': 2,
  120. 'no-redeclare': 2,
  121. 'no-regex-spaces': 2,
  122. 'no-return-assign': [2, 'except-parens'],
  123. 'no-self-assign': 2,
  124. 'no-self-compare': 2,
  125. 'no-sequences': 2,
  126. 'no-shadow-restricted-names': 2,
  127. 'no-spaced-func': 2,
  128. 'no-sparse-arrays': 2,
  129. 'no-this-before-super': 2,
  130. 'no-throw-literal': 2,
  131. 'no-trailing-spaces': 2,
  132. 'no-undef': 2,
  133. 'no-undef-init': 2,
  134. 'no-unexpected-multiline': 2,
  135. 'no-unmodified-loop-condition': 2,
  136. 'no-unneeded-ternary': [2, {
  137. 'defaultAssignment': false
  138. }],
  139. 'no-unreachable': 2,
  140. 'no-unsafe-finally': 2,
  141. 'no-unused-vars': [2, {
  142. 'vars': 'all',
  143. 'args': 'none'
  144. }],
  145. 'no-useless-call': 2,
  146. 'no-useless-computed-key': 2,
  147. 'no-useless-constructor': 2,
  148. 'no-useless-escape': 0,
  149. 'no-whitespace-before-property': 2,
  150. 'no-with': 2,
  151. 'one-var': [2, {
  152. 'initialized': 'never'
  153. }],
  154. 'operator-linebreak': [2, 'after', {
  155. 'overrides': {
  156. '?': 'before',
  157. ':': 'before'
  158. }
  159. }],
  160. 'padded-blocks': [2, 'never'],
  161. 'quotes': [2, 'single', {
  162. 'avoidEscape': true,
  163. 'allowTemplateLiterals': true
  164. }],
  165. 'semi': [2, 'never'],
  166. 'semi-spacing': [2, {
  167. 'before': false,
  168. 'after': true
  169. }],
  170. 'space-before-blocks': [2, 'always'],
  171. 'space-before-function-paren': [2, 'never'],
  172. 'space-in-parens': [2, 'never'],
  173. 'space-infix-ops': 2,
  174. 'space-unary-ops': [2, {
  175. 'words': true,
  176. 'nonwords': false
  177. }],
  178. 'spaced-comment': [2, 'always', {
  179. 'markers': ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ',']
  180. }],
  181. 'template-curly-spacing': [2, 'never'],
  182. 'use-isnan': 2,
  183. 'valid-typeof': 2,
  184. 'wrap-iife': [2, 'any'],
  185. 'yield-star-spacing': [2, 'both'],
  186. 'yoda': [2, 'never'],
  187. 'prefer-const': 2,
  188. 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
  189. 'object-curly-spacing': [2, 'always', {
  190. objectsInObjects: false
  191. }],
  192. 'array-bracket-spacing': [2, 'never']
  193. }
  194. }

2.9. beautify 与 Prettier - Code formatter

  • beautify:格式化代码的工具,可以格式化JSON|JS|HTML|CSS|SCSS,比内置格式化好用;但是react工程的jsx文件用beautify插件格式化会乱掉,建议不要用
  • Prettier - Code formatter:格式化代码的工具,可以支持react

    2.10. Bracket Pair Colorizer 或 Bracket Pair Colorizer2

    此扩展允许使用颜色标识匹配的括号。此扩展已经成为VSCode的一个本地功能(可以不安装)。直接修改 settings.json 文件开启即可 ``` { “editor.bracketPairColorization.enabled”: true, “editor.guides.bracketPairs”:”active” }
  1. ### 2.11. Auto Close Tag
  2. 自动添加HTML / XML关闭标签
  3. ### 2.12. Atuo Rename Tag
  4. 修改 html 标签,自动帮你完成尾部闭合标签的同步修改,不过有些bug
  5. ### 2.13. Highlight Matching Tag
  6. 高亮显示选中匹配标签
  7. ### 2.14. IntelliSense for CSS class names in HTML 或 HTML CSS Support
  8. **IntelliSense for CSS class names in HTML**<br />在 HTML 中调用定义好的样式名时,有时需要经常在 HTML CSS 文件之间切换,来回地查看你已定义好的 CSS 类名。 IntelliSense for CSS class names in HTML 插件,可以在 HTML 中需要调用 CSS 类名的地方,此插件会智能地给你已定义 CSS 类名的提示<br />**HTML CSS Support**<br />让 html 标签上写class 智能提示当前项目所支持的样式。新版已经支持scss文件检索
  9. ### 2.15. Vscode-element-helper
  10. 使用element-ui库的可以安装这个插件,编写标签时自动提示element标签名称。
  11. ### 2.16. cssrem
  12. 此插件的功能是实现 px 转换 rem
  13. 1. 安装插件
  14. 1. 打开【设置】(快捷键是 `ctrl + 逗号`
  15. 1. 设置html字体大小基准值,默认是16px
  16. 1. 使用时只需要将光标停留在一些px单位的值上,再按`Alt+z`,就可以换算成 rem 单位的值
  17. ### 2.17. 待整理
  18. - HTML Snippets
  19. - 超级实用且初级的 H5代码片段以及提示
  20. - Debugger for Chrome
  21. - vscode 映射 chrome debug功能,静态页面都可以用 vscode 来打断点调试,真666~。配置稍微复杂一些
  22. - jQuery Code Snippets
  23. - jquery 重度患者必须品
  24. - Npm Intellisense
  25. - require 时的包提示(最新版的vscode已经集成此功能)
  26. - Project Manager
  27. - 在多个项目之前快速切换的工具
  28. - VueHelper
  29. - snippet代码片段
  30. ![](https://gitee.com/moonzero/images/raw/master/code-note/20201106085236711_21502.jpg)
  31. ## 3. 常用配置
  32. ### 3.1. 出现CPU 100% 优化的设置
  33. 有时,vscode会出现CPU利用率100%的情况,两个rg.exe占用了全部的CPU。<br />解决办法:文件>首选项>设置, 搜索设置 `"search.followSymlinks" :false;`<br />![](https://gitee.com/moonzero/images/raw/master/code-note/20201106085401142_25165.jpg)<br />![](https://gitee.com/moonzero/images/raw/master/code-note/20201106085408474_25960.jpg)
  34. ### 3.2. 如何配置VSCODE打开文件总是在一个新的标签
  35. 经常搞混单击和双击的区别?这里在左侧资源管理器这边 如果单击文件是打开文件的预览模式,文件所在的标签上显示的文件名是 斜体状态,表明是在 预览模式,会被新打开的文件替换。所以如果是要打开文件进行编辑需要双击文件进行打开<br />如果要修改这个配置,可以找到以下配置字段进行调整:<br />如果要一起禁用预览模式,可以通过在设置文件中将“`workbench.editor.enablePreview`”属性设置为`false`来实现。还要注意“`workbench.editor.enablePreviewFromQuickOpen`”选项,以防您只想从快速打开菜单禁用此选项。<br />在您可以禁用预览模式之前,您需要打开您的Settings File。<br />专业提示:您可以使用Command Palette打开您的设置文件,只需输入“首选项:打开用户设置”!<br />打开设置文件(您的设置文件应位于右侧)后,添加“`workbench.editor.enablePreview`”属性,并将其值设置为`false`。<br />![](https://gitee.com/moonzero/images/raw/master/code-note/20201106085545739_7091.jpg)<br />![](https://gitee.com/moonzero/images/raw/master/code-note/20201106085551962_7405.jpg)
  36. ### 3.3. 设置tab为4个空格与格式化时缩进4个空格
  37. tab的宽度设置<br />![](https://gitee.com/moonzero/images/raw/master/code-note/20201106085633573_17435.jpg)<br />格式化缩进<br />![](https://gitee.com/moonzero/images/raw/master/code-note/20201106085641403_18541.jpg)
  38. ## 4. 快捷键
  39. ### 4.1. 官方快捷键列表
  40. - 官网地址:[https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf)
  41. - windows 快捷键
  42. ![](../../note_attachments/99-%E5%85%B6%E4%BB%96/Visual-Studio-Code/keyboard-shortcuts-windows.jpg)
  43. ### 4.2. 常用快捷键
  44. - `ctrl+shift+L` 批量修改变量名称
  45. ### 4.3. 多行编辑操作
  46. VScode对多行编辑有两种模式。
  47. #### 4.3.1. 第一种模式
  48. 竖列选择:长按`Alt+Shift`,按左键拖动鼠标选择多行。这种模式下只可以选择竖列,不可以随意插入光标。所以只限制于同一列且不间隔的情况下
  49. #### 4.3.2. 第二种模式
  50. - 竖列选择:`Shift+Ctrl`
  51. - 选择多个编辑位点:`Ctrl+光标点击`
  52. 这种模式下不仅可以选择竖列,同时还可以在多个地方插入光标
  53. #### 4.3.3. 两种模式的切换
  54. 使用`Ctrl+Shift+p`快捷键调用查询输入栏,输入“cursor”,列表中会出现“切换多行修改键”这个选项。选择这个选项就可以在两种模式下切换
  55. ## 5. VSCode拓展推荐(前端开发)【网络资源】
  56. [https://github.com/varHarrie/varharrie.github.io/issues/10](https://github.com/varHarrie/varharrie.github.io/issues/10)
  57. > 最后更新于:2018-08-20 11:13:21
  58. ## 6. 个人首选项配置(网络资源,仅供参考)

{ “breadcrumbs.enabled”: true, “editor.tabSize”: 2, “editor.renderWhitespace”: “boundary”, “editor.cursorBlinking”: “smooth”, “editor.minimap.renderCharacters”: false, “editor.fontFamily”: “‘Fira Code’, ‘Droid Sans Mono’, ‘Courier New’, monospace, ‘Droid Sans Fallback’”, “editor.fontLigatures”: true, “explorer.confirmDragAndDrop”: false, “extensions.autoUpdate”: false, “files.insertFinalNewline”: true, “git.autofetch”: true, “git.path”: “F:\Program Files\Git\cmd\git.exe”, “search.exclude”: { “/node_modules”: true, “/dist”: true }, “typescript.locale”: “en”, “window.titleBarStyle”: “custom”, “window.title”: “${dirty}${activeEditorMedium}${separator}${rootName}”, “window.zoomLevel”: 1, “workbench.activityBar.visible”: true, “workbench.colorTheme”: “Plastic - deprioritised punctuation”, “workbench.iconTheme”: “vscode-great-icons”, “workbench.startupEditor”: “newUntitledFile”, “eslint.autoFixOnSave”: true, “eslint.validate”: [“javascript”, “javascriptreact”, “vue”], “vsicons.projectDetection.autoReload”: true, “vsicons.dontShowNewVersionMessage”: true, “tslint.autoFixOnSave”: true, “debugwrapper.wrappers”: { “default”: “console.log(‘$eSEL’, $SEL)” }, “prettier.tslintIntegration”: true, “cSpell.userWords”: [ “Unmount” ], “jest.autoEnable”: false, }

```