# VS Code 快速参考

*导航、编辑、多光标、终端、调试、扩展*

> Source: VS Code Documentation (code.visualstudio.com/docs) · MIT

## 导航

### 文件与符号导航

| Command | Description |
|---------|-------------|
| `Ctrl+P` | 按名称快速打开文件 |
| `Ctrl+Shift+P` | 命令面板 |
| `Ctrl+Shift+O` | 跳到文件中的符号 |
| `Ctrl+T` | 跳到工作区中的符号 |
| `Ctrl+G` | 跳到指定行号 |
| `F12` | 跳到定义 |
| `Alt+F12` | 预览定义 |
| `Shift+F12` | 查找所有引用 |
| `Ctrl+Shift+\` | 跳到匹配的括号 |

### 标签页与编辑器导航

| Command | Description |
|---------|-------------|
| `Ctrl+Tab` | 循环切换已打开的标签页 |
| `Ctrl+1 / 2 / 3` | 聚焦编辑器组 1 / 2 / 3 |
| `Ctrl+\` | 拆分编辑器 |
| `Ctrl+B` | 切换侧边栏 |
| `Ctrl+J` | 切换底部面板 |

## 编辑

### 行操作

| Command | Description |
|---------|-------------|
| `Ctrl+Shift+K` | 删除整行 |
| `Alt+Up / Down` | 向上/向下移动行 |
| `Shift+Alt+Up / Down` | 向上/向下复制行 |
| `Ctrl+Enter` | 在下方插入新行 |
| `Ctrl+Shift+Enter` | 在上方插入新行 |
| `Ctrl+Shift+[` | 折叠区块 |
| `Ctrl+Shift+]` | 展开区块 |

### 文本操作

| Command | Description |
|---------|-------------|
| `Ctrl+D` | 选中单词（重复添加下一个匹配项） |
| `Ctrl+Shift+L` | 选中所有与当前选区相同的内容 |
| `Ctrl+L` | 选中整行 |
| `Ctrl+/` | 切换行注释 |
| `Shift+Alt+A` | 切换块注释 |
| `Tab / Shift+Tab` | 增加/减少缩进 |

## 多光标

### 添加光标

| Command | Description |
|---------|-------------|
| `Alt+Click` | 在点击位置添加光标 |
| `Ctrl+Alt+Up / Down` | 在上方/下方添加光标 |
| `Ctrl+D` | 添加下一个相同词的光标 |
| `Ctrl+Shift+L` | 在所有匹配处添加光标 |
| `Ctrl+U` | 撤销上次添加的光标 |
| `Esc` | 退出多光标模式 |

### 多光标工作流

```
// Select a word, then Ctrl+D to add matches
// Type replacement — all cursors update
// Ctrl+Shift+L selects ALL matches at once
// Alt+Click for arbitrary cursor placement
```

## 终端

### 终端快捷键

| Command | Description |
|---------|-------------|
| `Ctrl+`` | 切换集成终端 |
| `Ctrl+Shift+`` | 新建终端 |
| `Ctrl+Shift+5` | 拆分终端 |
| `Ctrl+PgUp / PgDn` | 向上/向下滚动终端 |
| `Ctrl+Shift+C` | 复制终端中的选区 |
| `Ctrl+Shift+V` | 粘贴到终端 |

### 终端管理

| Command | Description |
|---------|-------------|
| `Ctrl+Shift+P → Terminal: Kill` | 终止当前终端 |
| `Ctrl+Shift+P → Terminal: Rename` | 重命名终端标签 |
| `Terminal dropdown` | 在终端之间切换 |
| `terminal.integrated.shell.*` | 更改默认 shell 的设置项 |

## 调试

### 调试控制

| Command | Description |
|---------|-------------|
| `F5` | 开始 / 继续调试 |
| `Shift+F5` | 停止调试 |
| `Ctrl+Shift+F5` | 重启调试 |
| `F9` | 切换断点 |
| `F10` | 单步跳过 |
| `F11` | 单步进入 |
| `Shift+F11` | 单步跳出 |

### launch.json 示例

```
{
  "type": "node",
  "request": "launch",
  "name": "Run App",
  "program": "${workspaceFolder}/app.js"
}
```

### 调试功能

| Command | Description |
|---------|-------------|
| `Watch panel` | 调试时监视表达式 |
| `Call Stack` | 查看调用栈 |
| `Debug Console` | 在断点处执行表达式 |
| `Conditional breakpoint` | 右键断点 → 编辑条件 |
| `Logpoint` | 记录日志但不暂停执行 |

## 扩展

### 扩展管理

| Command | Description |
|---------|-------------|
| `Ctrl+Shift+X` | 打开扩展视图 |
| `@installed` | 筛选已安装的扩展 |
| `@enabled / @disabled` | 按启用/禁用状态筛选 |
| `@recommended` | 显示推荐扩展 |

### 常用扩展

| Command | Description |
|---------|-------------|
| `Prettier` | 代码格式化（JS、TS、CSS、HTML） |
| `ESLint` | JavaScript/TypeScript 代码检查 |
| `GitLens` | 增强 Git 集成与 blame 信息 |
| `Remote - SSH` | 通过 SSH 在远程机器上开发 |
| `Live Server` | 带热重载的本地开发服务器 |
| `Thunder Client` | VS Code 内置的 REST API 客户端 |

## 设置

### 访问设置

| Command | Description |
|---------|-------------|
| `Ctrl+,` | 打开设置 UI |
| `Ctrl+Shift+P → settings.json` | 打开设置 JSON 文件 |

### 常用设置（JSON）

```
{
  "editor.fontSize": 14,
  "editor.tabSize": 2,
  "editor.formatOnSave": true,
  "editor.wordWrap": "on",
  "files.autoSave": "afterDelay"
}
```

### 工作区 vs 用户

| Command | Description |
|---------|-------------|
| `User settings` | 全局设置，应用于所有项目 |
| `Workspace settings` | 按项目设置，存储在 .vscode/settings.json |
| `Workspace overrides User` | 工作区设置优先级更高 |

## 快捷键

### 自定义快捷键

| Command | Description |
|---------|-------------|
| `Ctrl+K Ctrl+S` | 打开键盘快捷键编辑器 |
| `keybindings.json` | 自定义绑定的 JSON 文件 |

### 核心快捷键

| Command | Description |
|---------|-------------|
| `Ctrl+Shift+P` | 命令面板（访问所有功能） |
| `Ctrl+P` | 快速打开文件 |
| `Ctrl+Shift+F` | 跨文件搜索 |
| `Ctrl+H` | 文件内查找与替换 |
| `Ctrl+Shift+H` | 跨文件查找与替换 |
| `F2` | 重命名符号 |
| `Ctrl+.` | 快速修复（代码操作） |
| `Ctrl+Space` | 触发 IntelliSense |
| `Ctrl+Shift+I` | 格式化文档 |

## Git 集成

### 源代码控制视图

| Command | Description |
|---------|-------------|
| `Ctrl+Shift+G` | 打开源代码控制面板 |
| `+` | 暂存变更（在 SCM 视图中） |
| `-` | 取消暂存 |
| `Ctrl+Enter` | 提交已暂存的变更 |
| `...` | 更多操作（push、pull 等） |

### 内联 Git 功能

| Command | Description |
|---------|-------------|
| `Gutter indicators` | 绿/蓝/红标记分别表示新增/修改/删除 |
| `Ctrl+Shift+P → Git: Checkout` | 切换分支 |
| `Ctrl+Shift+P → Git: Pull` | 从远端拉取 |
| `Ctrl+Shift+P → Git: Push` | 推送到远端 |
| `Click gutter change` | 查看修改行的内联 diff |

### Diff 与合并

| Command | Description |
|---------|-------------|
| `SCM → Open Changes` | 左右对比 diff 视图 |
| `Inline diff arrows` | 撤销单个变更 |
| `3-way merge editor` | 可视化解决冲突（1.69+） |

## 常用模式

### 工作区功能

| Command | Description |
|---------|-------------|
| `Ctrl+Shift+E` | 聚焦文件资源管理器 |
| `Ctrl+Shift+D` | 聚焦调试视图 |
| `Ctrl+Shift+M` | 显示问题面板 |
| `Ctrl+K Ctrl+T` | 更换颜色主题 |
| `Ctrl+K Z` | 进入禅模式 |

### 代码片段

```
// File → Preferences → Configure Snippets
"Print": {
  "prefix": "log",
  "body": "console.log('$1');",
  "description": "Console log"
}
```

### 任务（tasks.json）

```
{
  "label": "build",
  "type": "shell",
  "command": "npm run build",
  "group": "build"
}
```
