VS Code 插件推荐与配置优化

用了五年 VS Code,踩过不少坑,也积累了一些配置经验。

必装插件

通用开发

插件作用推荐度
ESLint代码检查⭐⭐⭐⭐⭐
Prettier代码格式化⭐⭐⭐⭐⭐
GitLensGit 增强⭐⭐⭐⭐⭐
Error Lens行内错误提示⭐⭐⭐⭐
Code Spell Checker拼写检查⭐⭐⭐⭐
EditorConfig统一编辑器配置⭐⭐⭐⭐

前端开发

插件作用推荐度
Vue - OfficialVue 语法支持⭐⭐⭐⭐⭐
ES7+ React SnippetsReact 代码片段⭐⭐⭐⭐
Tailwind CSS IntelliSenseTailwind 智能提示⭐⭐⭐⭐⭐
Auto Rename Tag标签重命名⭐⭐⭐⭐
Path Intellisense路径提示⭐⭐⭐

提效工具

插件作用推荐度
GitHub CopilotAI 补全⭐⭐⭐⭐⭐
Turbo Console Log快速插入 console⭐⭐⭐⭐
TODO HighlightTODO 高亮⭐⭐⭐⭐
Live Server本地服务器⭐⭐⭐
REST ClientHTTP 请求测试⭐⭐⭐⭐

VS Code 界面

settings.json 配置

{
  // 字体
  "editor.fontFamily": "JetBrains Mono, Menlo, monospace",
  "editor.fontSize": 14,
  "editor.fontLigatures": true,

  // 格式化
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.tabSize": 2,
  "editor.insertSpaces": true,

  // 性能优化
  "files.watcherExclude": {
    "**/.git/**": true,
    "**/node_modules/**": true,
    "**/dist/**": true
  },
  "search.exclude": {
    "**/node_modules": true,
    "**/dist": true,
    "**/.git": true
  },

  // 界面
  "editor.minimap.enabled": false,
  "editor.lineNumbers": "relative",
  "editor.renderWhitespace": "boundary",
  "workbench.editor.enablePreview": false,

  // Git
  "git.autofetch": true,
  "git.confirmSync": false,
  "git.enableSmartCommit": true,

  // Emmet
  "emmet.includeLanguages": {
    "vue": "html",
    "javascript": "javascriptreact"
  }
}

快捷键

常用快捷键,背下来效率翻倍:

功能MacWindows
命令面板Cmd+Shift+PCtrl+Shift+P
快速打开文件Cmd+PCtrl+P
全局搜索Cmd+Shift+FCtrl+Shift+F
多光标Alt+ClickAlt+Click
复制当前行Cmd+Shift+KCtrl+Shift+K
移动当前行Alt+Up/DownAlt+Up/Down
格式化代码Shift+Alt+FShift+Alt+F
终端Ctrl+`Ctrl+`

快捷键提示

性能优化

禁用不必要的插件

插件多了会卡。只在需要的项目启用:

// .vscode/settings.json
{
  "extensions.ignoreRecommendations": true
}

大文件处理

{
  "files.maxMemoryForLargeFilesMB": 4096,
  "editor.largeFileOptimizations": true
}

排除目录

{
  "files.exclude": {
    "**/.git": true,
    "**/.DS_Store": true,
    "**/node_modules": true
  }
}

代码片段

自定义 snippet 提效:

// .vscode/javascript.code-snippets
{
  "Console Log": {
    "prefix": "clg",
    "body": ["console.log('$1:', $1);"],
    "description": "Console log with variable name"
  },
  "React Component": {
    "prefix": "rfc",
    "body": [
      "function ${1:ComponentName}() {",
      "  return (",
      "    <div>",
      "      $0",
      "    </div>",
      "  )",
      "}",
      "",
      "export default ${1:ComponentName}"
    ]
  }
}

工作区配置

团队协作时,项目根目录放 .vscode/settings.json

{
  "editor.tabSize": 2,
  "editor.formatOnSave": true,
  "typescript.tsdk": "node_modules/typescript/lib",
  "eslint.validate": [
    "javascript",
    "typescript",
    "vue"
  ]
}

保证团队配置一致。

终端配置

内置终端很好用:

{
  "terminal.integrated.fontSize": 13,
  "terminal.integrated.fontFamily": "JetBrains Mono",
  "terminal.integrated.defaultProfile.osx": "zsh",
  "terminal.integrated.defaultProfile.windows": "PowerShell"
}

远程开发

Remote - SSH 插件远程开发神器:

{
  "remote.SSH.remoteServerListenOnSocket": true,
  "remote.SSH.showLoginTerminal": true
}

配置 ~/.ssh/config:

Host myserver
  HostName 192.168.1.100
  User deploy
  IdentityFile ~/.ssh/id_rsa

总结

VS Code 的强大在于扩展生态。但插件不是越多越好,选对自己有用的。

我的原则:

  1. 功能重复的只留一个
  2. 不常用的禁用
  3. 团队统一配置

工具是为了提效,别花太多时间折腾配置。