最后更新于:2026年7月

VS Code 效率指南
VS Code:统治开发者的编辑器

VS Code 是 2026 年最流行的代码编辑器,没有之一。 根据 Stack Overflow 2025 开发者调查,VS Code 的使用率超过 74%,远超第二名 IntelliJ IDEA。

但很多人只用了 VS Code 20% 的功能——写代码、保存、终端跑命令。VS Code 其实是一个极其强大的开发平台,合理配置后可以提升 2-3 倍的开发效率。

本文从安装配置到高级技巧,带你全面掌握 VS Code。


一、安装与基础配置

1.1 安装 VS Code

macOS:

BASH
# Homebrew 安装(推荐)
brew install --cask visual-studio-code

# 或使用 Homebrew Cask
brew install --cask vscode

Windows:

BASH
# 官网下载
# https://code.visualstudio.com/

# winget
winget install Microsoft.VisualStudioCode

# Scoop
scoop install extras/vscode

Linux:

BASH
# Debian/Ubuntu
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
sudo apt update
sudo apt install code

# Arch (AUR)
yay -S visual-studio-code-bin

1.2 命令行使用

BASH
# 用 VS Code 打开文件
code file.txt

# 打开文件夹
code .

# 打开并比较两个文件
code --diff file1.txt file2.txt

# 打开并跳转到指定行
code --goto file.txt:10:5  # 第10行第5列

# 新窗口打开
code --new-window .

# 从 stdin 读取
echo "hello" | code -

# 查看版本
code --version

1.3 核心设置

打开设置:

推荐基础配置(settings.json):

JSONC
// 按 Cmd+Shift+P → "Open User Settings (JSON)"
{
  // ========== 编辑器基础 ==========
  "editor.fontSize": 14,
  "editor.fontFamily": "'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace",
  "editor.fontLigatures": true,
  "editor.tabSize": 2,
  "editor.insertSpaces": true,
  "editor.formatOnSave": true,
  "editor.formatOnPaste": true,
  "editor.minimap.enabled": false,
  "editor.wordWrap": "on",
  "editor.bracketPairColorization.enabled": true,
  "editor.guides.bracketPairs": "active",
  "editor.smoothScrolling": true,
  "editor.cursorBlinking": "smooth",
  "editor.cursorSmoothCaretAnimation": "on",
  "editor.linkedEditing": true,
  "editor.stickyScroll.enabled": true,
  "editor.stickyScroll.maxLineCount": 5,
  "editor.inlineSuggest.enabled": true,

  // ========== 文件管理 ==========
  "files.autoSave": "afterDelay",
  "files.autoSaveDelay": 1000,
  "files.exclude": {
    "**/.git": true,
    "**/.DS_Store": true,
    "**/node_modules": true,
    "**/dist": true,
    "**/coverage": true
  },
  "files.insertFinalNewline": true,
  "files.trimTrailingWhitespace": true,
  "files.hotExit": "onExitAndWindowClose",

  // ========== 搜索 ==========
  "search.exclude": {
    "**/node_modules": true,
    "**/dist": true,
    "**/.git": true,
    "**/package-lock.json": true,
    "**/yarn.lock": true
  },

  // ========== 终端 ==========
  "terminal.integrated.fontSize": 13,
  "terminal.integrated.fontFamily": "'JetBrains Mono', monospace",
  "terminal.integrated.scrollback": 10000,
  "terminal.integrated.defaultProfile.osx": "zsh",
  "terminal.integrated.defaultProfile.linux": "zsh",
  "terminal.integrated.defaultProfile.windows": "PowerShell",

  // ========== 工作台 ==========
  "workbench.colorTheme": "One Dark Pro",
  "workbench.iconTheme": "material-icon-theme",
  "workbench.startupEditor": "newUntitledFile",
  "workbench.editor.enablePreview": false,
  "workbench.editor.wrapTabs": true,
  "workbench.tree.indent": 12,
  "workbench.tree.renderIndentGuides": "always",

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

  // ========== 窗口 ==========
  "window.title": "${dirty} ${activeEditorShort} - ${rootName}",
  "window.zoomLevel": 0,
  "window.restoreWindows": "all"
}

1.4 推荐字体

编程字体推荐(均支持连字 Ligatures):

字体风格连字免费推荐度
JetBrains Mono现代⭐⭐⭐⭐⭐
Fira Code经典⭐⭐⭐⭐⭐
Cascadia Code微软⭐⭐⭐⭐
MonoLisa优雅⭐⭐⭐⭐⭐
Victor Mono斜体⭐⭐⭐⭐
Iosevka窄体⭐⭐⭐⭐

安装 JetBrains Mono:

BASH
# macOS
brew install --cask font-jetbrains-mono

# 或手动下载
# https://www.jetbrains.com/lp/mono/

二、核心快捷键

2.1 通用快捷键

快捷键macOSWindows/Linux功能
命令面板Cmd+Shift+PCtrl+Shift+P万能入口
快速打开Cmd+PCtrl+P按文件名打开
全局搜索Cmd+Shift+FCtrl+Shift+F全项目搜索
设置Cmd+,Ctrl+,打开设置
键盘快捷键Cmd+K Cmd+SCtrl+K Ctrl+S查看所有快捷键

2.2 编辑快捷键

快捷键macOSWindows/Linux功能
多光标Option+点击Alt+点击添加光标
选中下一个相同Cmd+DCtrl+D选中下一个匹配
选中所有相同Cmd+Shift+LCtrl+Shift+L选中所有匹配
向上/下复制行Shift+Option+↑/↓Shift+Alt+↑/↓复制当前行
向上/下移动行Option+↑/↓Alt+↑/↓移动当前行
删除行Cmd+Shift+KCtrl+Shift+K删除当前行
注释切换Cmd+/Ctrl+/行注释
块注释Shift+Option+AShift+Alt+A块注释
格式化文档Shift+Option+FShift+Alt+F格式化整个文件
格式化选中Cmd+K Cmd+FCtrl+K Ctrl+F格式化选中部分
折叠Option+Cmd+[Ctrl+Shift+[折叠代码
展开Option+Cmd+]Ctrl+Shift+]展开代码
全折叠Cmd+K Cmd+0Ctrl+K Ctrl+0折叠所有
全展开Cmd+K Cmd+JCtrl+K Ctrl+J展开所有
跳转到行Ctrl+GCtrl+G跳转到指定行
跳转到符号Cmd+Shift+OCtrl+Shift+O跳转到文件内符号
跳转到定义F12F12跳转到定义
查看定义Option+F12Alt+F12浮窗查看定义
查找所有引用Shift+F12Shift+F12查找引用

2.3 窗口与面板

快捷键macOSWindows/Linux功能
侧边栏Cmd+BCtrl+B切换侧边栏
面板(终端)Cmd+JCtrl+J切换底部面板
资源管理器Cmd+Shift+ECtrl+Shift+E聚焦文件列表
搜索Cmd+Shift+FCtrl+Shift+F全局搜索
GitCtrl+Shift+GCtrl+Shift+GGit 面板
调试Cmd+Shift+DCtrl+Shift+D调试面板
扩展Cmd+Shift+XCtrl+Shift+X扩展面板
新窗口Cmd+Shift+NCtrl+Shift+N新开窗口
关闭标签Cmd+WCtrl+W关闭当前标签
分屏Cmd+\Ctrl+\左右分屏
切换分屏Cmd+1/2/3Ctrl+1/2/3切换到分屏1/2/3
终端Ctrl+``Ctrl+``打开终端

2.4 高效编辑技巧

技巧1:多光标编辑

PLAINTEXT
1. Cmd+D  → 逐个选中相同的词
2. Cmd+Shift+L → 一次性选中所有相同的词
3. Option+点击 → 在任意位置添加光标
4. Option+Shift+I → 在选中行的行尾添加光标

技巧2:快速重构

PLAINTEXT
1. F2 → 重命名变量/函数(全局替换)
2. Cmd+. → 快速修复(导入缺失的模块等)
3. Cmd+Shift+O → 跳转到文件内符号
4. Cmd+T → 跳转到工作区符号

技巧3:Emmet(HTML/CSS 快捷输入)

HTML
<!-- 输入: div.container>ul>li*5 -->
<!-- 生成: -->
<div class="container">
  <ul>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
  </ul>
</div>

<!-- 输入: button.btn.btn-primary{点击我} -->
<!-- 生成: -->
<button class="btn btn-primary">点击我</button>

三、必装扩展推荐

3.1 通用扩展

扩展说明推荐度
GitLensGit 超级增强⭐⭐⭐⭐⭐
Prettier代码格式化⭐⭐⭐⭐⭐
ESLintJavaScript/TypeScript 检查⭐⭐⭐⭐⭐
Error Lens错误信息直接显示在行尾⭐⭐⭐⭐⭐
Material Icon Theme文件图标主题⭐⭐⭐⭐⭐
One Dark Pro暗色主题⭐⭐⭐⭐⭐
Path Intellisense路径自动补全⭐⭐⭐⭐
Project Manager项目快速切换⭐⭐⭐⭐
Code Spell Checker拼写检查⭐⭐⭐⭐
Todo TreeTODO 注释管理⭐⭐⭐⭐
indent-rainbow缩进彩虹色⭐⭐⭐⭐
Bracket Pair Colorizer括号配对着色⭐⭐⭐⭐
Better Comments注释分类高亮⭐⭐⭐⭐
Bookmarks代码书签⭐⭐⭐⭐

3.2 前端开发扩展

扩展说明推荐度
ES7+ React/Redux SnippetsReact 代码片段⭐⭐⭐⭐⭐
Tailwind CSS IntelliSenseTailwind 智能提示⭐⭐⭐⭐⭐
Auto Rename Tag自动重命名配对标签⭐⭐⭐⭐⭐
CSS ModulesCSS Modules 支持⭐⭐⭐⭐
Path Autocomplete路径自动补全⭐⭐⭐⭐
Import Cost显示导入包大小⭐⭐⭐⭐
Console Ninjaconsole.log 增强⭐⭐⭐⭐
esbuild Problem Matchers构建错误匹配⭐⭐⭐

3.3 后端开发扩展

扩展说明推荐度
PythonPython 语言支持⭐⭐⭐⭐⭐
PylancePython 类型检查⭐⭐⭐⭐⭐
GoGo 语言支持⭐⭐⭐⭐⭐
Java Extension PackJava 开发包⭐⭐⭐⭐⭐
Rust-analyzerRust 语言支持⭐⭐⭐⭐⭐
DockerDocker 容器管理⭐⭐⭐⭐⭐
Database Client数据库管理⭐⭐⭐⭐
REST ClientAPI 测试工具⭐⭐⭐⭐⭐
Thunder ClientAPI 测试(类似 Postman)⭐⭐⭐⭐

3.4 工具类扩展

扩展说明推荐度
Live Server本地开发服务器⭐⭐⭐⭐⭐
Git GraphGit 分支图形化⭐⭐⭐⭐⭐
GitHub Pull RequestsPR 管理⭐⭐⭐⭐⭐
Remote - SSH远程开发⭐⭐⭐⭐⭐
Remote - Containers容器开发⭐⭐⭐⭐⭐
Dev Containers开发容器⭐⭐⭐⭐
YAMLYAML 语言支持⭐⭐⭐⭐
Markdown All in OneMarkdown 增强⭐⭐⭐⭐
Markdown Preview EnhancedMarkdown 预览增强⭐⭐⭐⭐
SVGSVG 预览和编辑⭐⭐⭐

3.5 AI 辅助扩展

扩展说明推荐度
GitHub CopilotAI 代码补全⭐⭐⭐⭐⭐
GitHub Copilot ChatAI 对话编程⭐⭐⭐⭐⭐
Codeium免费 AI 补全替代⭐⭐⭐⭐
TabnineAI 代码补全⭐⭐⭐⭐
Cody (Sourcegraph)AI 代码助手⭐⭐⭐⭐
CursorAI 编辑器集成⭐⭐⭐⭐

四、主题美化

4.1 推荐主题

暗色主题:

亮色主题:

4.2 图标主题

4.3 个性化配置

JSONC
{
  // 主题
  "workbench.colorTheme": "Tokyo Night",
  "workbench.iconTheme": "material-icon-theme",
  
  // 自定义颜色
  "workbench.colorCustomizations": {
    "editor.background": "#1a1b26",
    "editor.lineHighlightBackground": "#292e42",
    "editorCursor.foreground": "#c0caf5",
    "editorLineNumber.foreground": "#3b4261",
    "editorLineNumber.activeForeground": "#7aa2f7",
  },
  
  // 字体
  "editor.fontSize": 14,
  "editor.lineHeight": 22,
  "editor.fontFamily": "'JetBrains Mono', monospace",
  "editor.fontLigatures": true,
  "editor.letterSpacing": 0.5,
  
  // 光标
  "editor.cursorBlinking": "smooth",
  "editor.cursorSmoothCaretAnimation": "on",
  "editor.cursorWidth": 2,
  
  // 滚动条
  "editor.scrollbar.vertical": "auto",
  "editor.scrollbar.horizontal": "auto",
  "editor.scrollbar.verticalScrollbarSize": 8,
  
  // 透明度(macOS)
  "window.background": "#1a1b26ee",
}

五、代码片段(Snippets)

5.1 自定义代码片段

创建代码片段:

PLAINTEXT
Cmd+Shift+P → "Configure User Snippets" → 选择语言

示例:TypeScript React 代码片段

JSONC
// snippets/typescriptreact.json
{
  "React Functional Component": {
    "prefix": "rfc",
    "body": [
      "import { FC } from 'react';",
      "",
      "interface ${1:ComponentName}Props {",
      "  $2",
      "}",
      "",
      "const ${1:ComponentName}: FC<${1:ComponentName}Props> = ($3) => {",
      "  return (",
      "    <div>",
      "      $0",
      "    </div>",
      "  );",
      "};",
      "",
      "export default ${1:ComponentName};"
    ],
    "description": "React 函数组件 + TypeScript"
  },
  
  "React useState Hook": {
    "prefix": "useState",
    "body": [
      "const [${1:state}, set${1/(.*)/${1:/capitalize}/}] = useState<${2:type}>(${3:initialValue});"
    ],
    "description": "useState Hook"
  },
  
  "React useEffect Hook": {
    "prefix": "useEffect",
    "body": [
      "useEffect(() => {",
      "  $0",
      "}, [$1]);"
    ],
    "description": "useEffect Hook"
  },
  
  "Console Log": {
    "prefix": "clg",
    "body": ["console.log('$1:', $1);"],
    "description": "console.log"
  },
  
  "Try Catch": {
    "prefix": "tryc",
    "body": [
      "try {",
      "  $0",
      "} catch (error) {",
      "  console.error('Error:', error);",
      "}"
    ],
    "description": "try catch"
  }
}

5.2 常用代码片段前缀

前缀展开内容
rfcReact 函数组件
rafceReact 箭头函数组件
useStateuseState Hook
useEffectuseEffect Hook
useCallbackuseCallback Hook
useMemouseMemo Hook
clgconsole.log
tryctry-catch 块
expexport
imdimport destructuring

六、调试技巧

6.1 基础调试

创建 launch.json:

PLAINTEXT
Cmd+Shift+P → "Debug: Open launch.json" → 选择环境

Node.js 调试配置:

JSONC
// .vscode/launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug Current File",
      "type": "node",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "skipFiles": ["<node_internals>/**"]
    },
    {
      "name": "Debug npm start",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "npm",
      "runtimeArgs": ["run", "dev"],
      "console": "integratedTerminal"
    },
    {
      "name": "Attach to Process",
      "type": "node",
      "request": "attach",
      "processId": "${command:PickProcess}"
    }
  ]
}

6.2 断点类型

类型说明使用方式
行断点执行到该行暂停点击行号左侧
条件断点满足条件才暂停右键行号 → Add Conditional Breakpoint
日志断点不暂停,只输出日志右键行号 → Add Logpoint
函数断点函数被调用时暂停断点面板 → + 添加函数名
异常断点抛出异常时暂停断点面板 → 异常断点

条件断点示例:

PLAINTEXT
条件表达式:
- i === 5
- user.age > 18
- str.includes("error")
- count % 100 === 0

6.3 调试操作

快捷键macOSWindows/Linux功能
开始调试F5F5启动调试
继续F5F5继续到下一个断点
单步跳过F10F10执行下一行(不进入函数)
单步进入F11F11进入函数内部
单步跳出Shift+F11Shift+F11跳出当前函数
重启Shift+Cmd+F5Shift+Ctrl+F5重启调试
停止Shift+F5Shift+F5停止调试
切换断点F9F9启用/禁用断点

6.4 前端调试

Chrome 调试集成:

JSONC
// launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Chrome",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:3000",
      "webRoot": "${workspaceFolder}/src"
    },
    {
      "name": "Attach to Chrome",
      "type": "chrome",
      "request": "attach",
      "port": 9222,
      "webRoot": "${workspaceFolder}/src"
    }
  ]
}

七、终端集成

7.1 集成终端配置

JSONC
{
  // 终端外观
  "terminal.integrated.fontSize": 13,
  "terminal.integrated.lineHeight": 1.2,
  "terminal.integrated.fontFamily": "'JetBrains Mono', monospace",
  "terminal.integrated.cursorStyle": "line",
  "terminal.integrated.scrollback": 10000,
  
  // 终端行为
  "terminal.integrated.enablePersistentSessions": true,
  "terminal.integrated.copyOnSelection": true,
  "terminal.integrated.rightClickBehavior": "paste",
  "terminal.integrated.confirmOnExit": "never",
  "terminal.integrated.confirmOnKill": "never",
  
  // macOS 特定
  "terminal.integrated.defaultProfile.osx": "zsh",
  "terminal.integrated.profiles.osx": {
    "zsh": {
      "path": "zsh",
      "args": ["-l"]
    }
  },
  
  // Windows 特定
  "terminal.integrated.defaultProfile.windows": "PowerShell",
  "terminal.integrated.profiles.windows": {
    "PowerShell": {
      "source": "PowerShell",
      "icon": "terminal-powershell"
    },
    "Git Bash": {
      "path": "C:\\Program Files\\Git\\bin\\bash.exe"
    }
  }
}

7.2 终端快捷键

快捷键macOSWindows/Linux功能
新终端Ctrl+``Ctrl+``打开终端
新终端分屏Cmd+\Ctrl+Shift+\左右分屏终端
切换终端Cmd+Shift+[ / ]Ctrl+Shift+[ / ]切换终端标签
清屏Cmd+KCtrl+K清空终端
搜索Cmd+FCtrl+F搜索终端输出
关闭终端Cmd+WCtrl+W关闭当前终端

7.3 任务(Tasks)

创建任务:

JSONC
// .vscode/tasks.json
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "dev",
      "type": "shell",
      "command": "pnpm dev",
      "group": "build",
      "isBackground": true,
      "problemMatcher": []
    },
    {
      "label": "build",
      "type": "shell",
      "command": "pnpm build",
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "problemMatcher": []
    },
    {
      "label": "test",
      "type": "shell",
      "command": "pnpm test",
      "group": "test"
    },
    {
      "label": "lint",
      "type": "shell",
      "command": "pnpm lint && pnpm format",
      "group": "build"
    }
  ]
}

运行任务:


八、远程开发

8.1 Remote - SSH

连接远程服务器:

PLAINTEXT
1. 安装 "Remote - SSH" 扩展
2. Cmd+Shift+P → "Remote-SSH: Connect to Host"
3. 输入 ssh user@hostname
4. 选择远程目录
5. VS Code 在远程服务器上运行

SSH 配置(~/.ssh/config):

PLAINTEXT
Host my-server
    HostName 192.168.1.100
    User root
    Port 22
    IdentityFile ~/.ssh/id_ed25519
    ForwardAgent yes

优势:

8.2 Dev Containers

使用 Docker 容器作为开发环境:

JSONC
// .devcontainer/devcontainer.json
{
  "name": "Node.js Development",
  "image": "mcr.microsoft.com/devcontainers/javascript-node:20",
  
  "features": {
    "ghcr.io/devcontainers/features/git:1": {},
    "ghcr.io/devcontainers/features/github-cli:1": {}
  },
  
  "forwardPorts": [3000, 5173],
  
  "postCreateCommand": "pnpm install",
  
  "customizations": {
    "vscode": {
      "extensions": [
        "dbaeumer.vscode-eslint",
        "esbenp.prettier-vscode",
        "eamodio.gitlens"
      ],
      "settings": {
        "editor.formatOnSave": true
      }
    }
  }
}

优势:

8.3 WSL 开发(Windows)

BASH
# 在 WSL 中安装 VS Code Server
code .

# 或在 VS Code 中
# Cmd+Shift+P → "WSL: Connect to WSL"

九、GitHub Copilot 集成

9.1 Copilot 基础

安装:

  1. 安装 “GitHub Copilot” 扩展
  2. 登录 GitHub 账号
  3. 确保订阅了 Copilot(或 Copilot Business)

基本使用:

PLAINTEXT
1. 写一个注释描述你想做什么
2. Copilot 自动生成代码建议(灰色文字)
3. Tab → 接受建议
4. Cmd+] / Cmd+[ → 切换下一个/上一个建议
5. Option+\ → 打开 Copilot 面板(多个建议)

9.2 Copilot Chat

PLAINTEXT
Cmd+Shift+I → 打开 Copilot Chat(侧边栏)

功能:
- "解释这段代码" → 选中代码后提问
- "写一个单元测试" → 选中函数后提问
- "修复这个 bug" → 描述问题
- "优化这段代码" → 选中代码后提问
- "这段代码有什么问题?" → 代码审查

内联聊天:
Cmd+I → 在代码中直接提问

9.3 Copilot 最佳实践

好的提示:

TYPESCRIPT
// 写一个函数,接收一个日期字符串,返回格式化后的日期
// 输入格式:YYYY-MM-DD
// 输出格式:2026年7月10日

// Copilot 会生成:
function formatDate(dateStr: string): string {
  const [year, month, day] = dateStr.split('-');
  return `${year}${parseInt(month)}${parseInt(day)}日`;
}

技巧:


十、Settings Sync(设置同步)

10.1 开启同步

PLAINTEXT
1. Cmd+Shift+P → "Settings Sync: Turn On"
2. 选择登录方式(GitHub 或 Microsoft)
3. 选择要同步的内容:
   ✅ Settings(设置)
   ✅ Keyboard Shortcuts(快捷键)
   ✅ Extensions(扩展)
   ✅ UI State(UI 状态)
   ✅ Snippets(代码片段)
   ✅ Profiles(配置文件)
4. 点击 "Sync" 开始同步

10.2 多设备同步

同步内容:

多设备使用:

10.3 配置文件(Profiles)

PLAINTEXT
Cmd+Shift+P → "Profiles: Create Profile"

创建多个配置文件:
- "前端开发" → React, Vue, Tailwind 扩展
- "后端开发" → Python, Go, Docker 扩展
- "写作" → Markdown, 拼写检查扩展
- "远程开发" → SSH, Containers 扩展

切换:点击左下角齿轮 → 切换 Profile

十一、效率提升技巧

11.1 50 个效率技巧

文件导航:

  1. Cmd+P 快速打开文件(支持模糊搜索)
  2. Cmd+P 输入 :行号 跳转到指定行
  3. Cmd+P 输入 @符号 跳转到文件内符号
  4. Cmd+T 搜索工作区所有符号
  5. Ctrl+Tab 切换最近打开的文件
  6. Ctrl+- / Ctrl+Shift+- 光标跳转历史

编辑效率: 7. Cmd+D 逐个选中相同词 → 批量修改 8. Cmd+Shift+L 一次性选中所有相同词 9. Option+Shift+I 在选中行行尾添加光标 10. Cmd+K M 快速切换语言模式 11. Cmd+/ 快速注释/取消注释 12. Option+↑/↓ 上下移动行 13. Shift+Option+↑/↓ 上下复制行 14. Cmd+K Cmd+X 修剪行尾空格 15. Cmd+K Cmd+0 全部折叠

搜索替换: 16. Cmd+F 当前文件搜索 17. Cmd+Option+F 当前文件替换 18. Cmd+Shift+F 全局搜索 19. Cmd+Shift+H 全局替换 20. 搜索时使用正则表达式 .*

终端效率: 21. Ctrl+`` 打开/关闭终端 22. Cmd+\ 终端左右分屏 23. Cmd+K 清空终端 24. Ctrl+Cmd+↑/↓ 终端上下滚动

Git 效率: 25. 源代码管理面板(Ctrl+Shift+G)→ 可视化 Git 26. 行内 blame(GitLens)→ 悬浮显示修改者 27. Cmd+Shift+G → 提交、推送、拉取一键操作 28. Git Graph 扩展 → 图形化分支历史

多光标编辑: 29. Option+点击 添加光标 30. Cmd+Option+Shift+↓/↑ 向下/上添加光标 31. Cmd+U 撤销最后一个光标 32. Esc 取消所有多光标

代码格式化: 33. Shift+Option+F 格式化整个文件 34. Cmd+K Cmd+F 格式化选中部分 35. formatOnSave 保存时自动格式化

快速操作: 36. Cmd+Shift+P 万能命令面板 37. Cmd+. 快速修复/代码操作 38. F2 重命名符号 39. F12 跳转到定义 40. Option+F12 浮窗查看定义 41. Shift+F12 查找所有引用 42. Cmd+Shift+O 跳转到文件内符号 43. Ctrl+G 跳转到指定行

窗口管理: 44. Cmd+B 切换侧边栏 45. Cmd+J 切换底部面板 46. Cmd+\ 左右分屏 47. Cmd+1/2/3 切换分屏组 48. Cmd+W 关闭标签 49. Cmd+Shift+W 关闭窗口 50. Cmd+Shift+N 新窗口

11.2 自定义快捷键

打开快捷键设置:

PLAINTEXT
Cmd+K Cmd+S → 键盘快捷键参考

在 keybindings.json 中自定义:

JSONC
// keybindings.json
[
  // 快速创建新文件
  {
    "key": "cmd+n cmd+n",
    "command": "workbench.action.files.newUntitledFile"
  },
  
  // 在 Finder 中显示
  {
    "key": "cmd+shift+r",
    "command": "revealFileInOS",
    "when": "editorFocus"
  },
  
  // 复制文件路径
  {
    "key": "cmd+shift+c",
    "command": "workbench.action.files.copyPathOfActiveFile"
  },
  
  // 切换终端
  {
    "key": "ctrl+`",
    "command": "workbench.action.terminal.toggleTerminal"
  },
  
  // 格式化文档
  {
    "key": "shift+alt+f",
    "command": "editor.action.formatDocument"
  }
]

十二、项目级配置

12.1 .vscode 目录

项目推荐的 .vscode 配置:

PLAINTEXT
.vscode/
├── settings.json     # 项目设置
├── launch.json       # 调试配置
├── tasks.json        # 任务配置
└── extensions.json   # 推荐扩展

settings.json:

JSONC
{
  // 编辑器设置
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": "explicit",
    "source.organizeImports": "explicit"
  },
  
  // 文件类型关联
  "files.associations": {
    "*.css": "tailwindcss"
  },
  
  // ESlint
  "eslint.validate": [
    "javascript",
    "typescript",
    "javascriptreact",
    "typescriptreact"
  ],
  
  // TypeScript
  "typescript.tsdk": "node_modules/typescript/lib",
  "typescript.enablePromptUseWorkspaceTsdk": true,
  
  // 路径别名
  "path-intellisense.extensionOnImport": true,
  "path-intellisense.mappings": {
    "@": "${workspaceRoot}/src",
    "@components": "${workspaceRoot}/src/components"
  }
}

extensions.json:

JSONC
{
  "recommendations": [
    "dbaeumer.vscode-eslint",
    "esbenp.prettier-vscode",
    "eamodio.gitlens",
    "ms-azuretools.vscode-docker",
    "bradlc.vscode-tailwindcss",
    "ms-vscode.vscode-typescript-next"
  ]
}

当团队成员打开项目时,VS Code 会提示安装推荐扩展。

12.2 EditorConfig

INI
# .editorconfig
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

十三、常见问题

Q1:VS Code 太卡怎么办?

优化方案:

PLAINTEXT
1. 禁用不用的扩展
   → 扩展面板 → 禁用不需要的

2. 排除大文件夹
   → settings.json → files.exclude / search.exclude

3. 关闭文件监视
   → "files.watcherExclude": {"**/node_modules/**": true}

4. 增加内存限制
   → "files.maxMemoryForLargeFilesMB": 8192

5. 关闭不必要的功能
   → minimap, semantic highlighting 等

Q2:扩展太多变慢怎么办?

PLAINTEXT
1. 使用 Profiles 按需启用扩展
2. 只在特定项目启用特定扩展
3. 卸载不用的扩展
4. 使用 "Disable (Workspace)" 而非全局禁用

Q3:如何同步多台电脑的配置?

PLAINTEXT
Settings Sync:
1. 用 GitHub 账号登录
2. 开启同步
3. 在新电脑上登录同一账号
4. 自动同步所有设置、扩展、快捷键

Q4:终端中文乱码怎么办?

JSONC
// settings.json
{
  "terminal.integrated.profiles.osx": {
    "zsh": {
      "path": "zsh",
      "args": ["-l"],
      "env": {
        "LANG": "en_US.UTF-8",
        "LC_ALL": "en_US.UTF-8"
      }
    }
  }
}

十四、总结

VS Code 配置清单

效率提升路线图

PLAINTEXT
入门级(第1周):
  → 掌握基本快捷键(Cmd+P, Cmd+Shift+P, Cmd+D)
  → 安装基础扩展
  → 配置主题和字体

进阶级(第2-3周):
  → 掌握多光标编辑
  → 使用 Git 集成
  → 配置代码片段
  → 调试功能

高级(第1-2月):
  → 自定义任务和调试配置
  → 远程开发
  → Copilot 集成
  → Dev Containers

大师级(第3月+):
  → Profiles 多环境管理
  → 自定义扩展开发
  → 团队配置标准化
  → 端到端 DevOps 集成


VS Code 的强大远超你的想象。 投入一点时间学习和配置,你的开发效率会得到质的飞跃。记住:工具是为你服务的,而不是反过来。🚀

版权声明

作者: 易邦

链接: https://blog.e8k.net/posts/vscode-complete-guide-2026/

许可证: 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。