最后更新于: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 通用快捷键

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

2.2 编辑快捷键

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

2.3 窗口与面板

快捷键 macOS Windows/Linux 功能
侧边栏 Cmd+B Ctrl+B 切换侧边栏
面板(终端) Cmd+J Ctrl+J 切换底部面板
资源管理器 Cmd+Shift+E Ctrl+Shift+E 聚焦文件列表
搜索 Cmd+Shift+F Ctrl+Shift+F 全局搜索
Git Ctrl+Shift+G Ctrl+Shift+G Git 面板
调试 Cmd+Shift+D Ctrl+Shift+D 调试面板
扩展 Cmd+Shift+X Ctrl+Shift+X 扩展面板
新窗口 Cmd+Shift+N Ctrl+Shift+N 新开窗口
关闭标签 Cmd+W Ctrl+W 关闭当前标签
分屏 Cmd+\ Ctrl+\ 左右分屏
切换分屏 Cmd+1/2/3 Ctrl+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 通用扩展

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

3.2 前端开发扩展

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

3.3 后端开发扩展

扩展 说明 推荐度
Python Python 语言支持 ⭐⭐⭐⭐⭐
Pylance Python 类型检查 ⭐⭐⭐⭐⭐
Go Go 语言支持 ⭐⭐⭐⭐⭐
Java Extension Pack Java 开发包 ⭐⭐⭐⭐⭐
Rust-analyzer Rust 语言支持 ⭐⭐⭐⭐⭐
Docker Docker 容器管理 ⭐⭐⭐⭐⭐
Database Client 数据库管理 ⭐⭐⭐⭐
REST Client API 测试工具 ⭐⭐⭐⭐⭐
Thunder Client API 测试(类似 Postman) ⭐⭐⭐⭐

3.4 工具类扩展

扩展 说明 推荐度
Live Server 本地开发服务器 ⭐⭐⭐⭐⭐
Git Graph Git 分支图形化 ⭐⭐⭐⭐⭐
GitHub Pull Requests PR 管理 ⭐⭐⭐⭐⭐
Remote - SSH 远程开发 ⭐⭐⭐⭐⭐
Remote - Containers 容器开发 ⭐⭐⭐⭐⭐
Dev Containers 开发容器 ⭐⭐⭐⭐
YAML YAML 语言支持 ⭐⭐⭐⭐
Markdown All in One Markdown 增强 ⭐⭐⭐⭐
Markdown Preview Enhanced Markdown 预览增强 ⭐⭐⭐⭐
SVG SVG 预览和编辑 ⭐⭐⭐

3.5 AI 辅助扩展

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

四、主题美化

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 常用代码片段前缀

前缀 展开内容
rfc React 函数组件
rafce React 箭头函数组件
useState useState Hook
useEffect useEffect Hook
useCallback useCallback Hook
useMemo useMemo Hook
clg console.log
tryc try-catch 块
exp export
imd import 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 调试操作

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

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 终端快捷键

快捷键 macOS Windows/Linux 功能
新终端 Ctrl+`` Ctrl+`` 打开终端
新终端分屏 Cmd+\ Ctrl+Shift+\ 左右分屏终端
切换终端 Cmd+Shift+[ / ] Ctrl+Shift+[ / ] 切换终端标签
清屏 Cmd+K Ctrl+K 清空终端
搜索 Cmd+F Ctrl+F 搜索终端输出
关闭终端 Cmd+W Ctrl+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 国际许可协议进行许可。