起因
新机器 VSCode 装上后大家第一件事是装一堆插件:bracket pair colorizer / icon
theme / 各种 snippet。其实 VSCode 内置功能已经很强,不知道反而错过。
下面是我每天用、新人常不知道的 12 个原生功能。
1. 多光标编辑
Alt+Click 加一个光标
Ctrl+D 选中下一个相同 word(继续按 Ctrl+D 选更多)
Ctrl+Shift+L 选中所有相同 word
Alt+Shift+I 多行末尾各加一个光标(先选多行)
Ctrl+Alt+↓/↑ 垂直加光标(多行同列编辑)
例:选中变量名 old → 几次 Ctrl+D → 同时改 5 处。
比 find/replace 快 10 倍(避免改到不该改的)。
2. 命令面板(Command Palette)
Ctrl+Shift+P 命令面板
VSCode 所有功能都在这里。打 "format" 找格式化命令;打 ">git" 找
git 操作;打 "Reload" 重启 window。
派生:
Ctrl+P 快速打开文件(fuzzy)
Ctrl+Shift+O 当前文件 symbol 跳转
Ctrl+T workspace 全局 symbol 跳转
Ctrl+G 跳行号
Ctrl+@ 查看 outline
记 Ctrl+P / Ctrl+Shift+P / Ctrl+Shift+O 三个就够日常。
3. 集成 terminal
Ctrl+` 打开 / 切换 terminal
Ctrl+Shift+` 新 terminal
terminal 支持 split / multiple shell / link 点击文件路径直接跳过去。
不用切窗口看输出。
4. Source Control(git 集成)
Ctrl+Shift+G Source Control 视图
- 看 diff(点 modified 文件)
- 提交(输入 message + Ctrl+Enter)
- stage hunk(左侧 ± 按钮)
- branch 切换(左下角 status bar)
- 推送 / 拉取(status bar 同步图标)
复杂的 rebase / 解 conflict 也有原生 UI。
GitLens 插件加强(line blame / file history 直观),但基础够用。
5. 多文件 search & replace
Ctrl+Shift+F workspace 搜索
Ctrl+Shift+H workspace 替换
- 支持 regex(小图标 .*)
- preserve case(保留大小写:oldVar → newName,OldVar → NewName)
- include / exclude 文件 glob
- 全选预览后 replace all
替代很多自己写 sed 脚本的场景。
6. snippets
Ctrl+Space 补全(如果 LSP 没自动弹)
Tab 接受补全
自带 snippets:for、if、function 等输入触发模板。
自定义:
File → Preferences → Configure User Snippets → typescript.json
{
"Console Log": {
"prefix": "clog",
"body": ["console.log('${1:label}:', ${2:value})"],
"description": "log with label"
}
}
输入 clog + Tab → console.log('label:', value),光标在 label。
7. emmet(HTML / CSS / JSX)
div.container>ul>li*5>a[href="#"]{Item $}+Tab
→
<div class="container">
<ul>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
<li><a href="#">Item 5</a></li>
</ul>
</div>
CSS:m10p → margin: 10px;。HTML 模板秒生成。
8. zen 模式 / 双 editor
Ctrl+K Z zen mode(隐藏所有 UI)
Ctrl+\ split editor 左右
Ctrl+1 / Ctrl+2 切到第 1 / 2 个 editor
Ctrl+W 关当前 editor
复杂 review 时左 test 右 code 并排。
9. 自定义 keymap
File → Preferences → Keyboard Shortcuts:
- 搜命令名(如"toggle terminal")→ 改 binding
- 写 keybindings.json:
[
{ "key": "ctrl+j", "command": "workbench.action.terminal.toggleTerminal" },
{ "key": "ctrl+shift+j", "command": "editor.action.joinLines" }
]
Vim 用户装 vscode-neovim(不是 vim 插件)能用真 nvim 引擎,几乎 100%
vim 体验。
10. workspace 设置
.vscode/settings.json 进 git,团队成员共享:
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixAll.eslint": "explicit"
},
"editor.rulers": [80, 100],
"files.exclude": {
"**/__pycache__": true,
"**/.pytest_cache": true,
"**/node_modules": true
},
"search.exclude": {
"**/dist": true,
"**/.venv": true
},
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
新人 clone 后 IDE 自动应用这些设置:format on save、自动 organize
imports、文件树过滤 pycache 等。
11. tasks(不离开 IDE 跑命令)
.vscode/tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "test",
"type": "shell",
"command": "pytest -xvs",
"group": { "kind": "test", "isDefault": true }
},
{
"label": "dev",
"type": "shell",
"command": "npm run dev",
"isBackground": true,
"presentation": { "reveal": "always", "panel": "dedicated" }
}
]
}
Ctrl+Shift+P → Tasks: Run Task → test 跑。
test failures 自动跳到对应行 + 显示 error。
12. launch.json (debugger)
.vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}"
},
{
"name": "Django",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": ["runserver", "--noreload"],
"django": true
},
{
"name": "FastAPI",
"type": "debugpy",
"request": "launch",
"module": "uvicorn",
"args": ["app.main:app", "--reload"]
},
{
"name": "Node: Attach",
"type": "node",
"request": "attach",
"port": 9229
}
]
}
F5 启动 debugger,breakpoint / watch / call stack 全 GUI。
对 Python / Node 项目调试效率秒杀 print。
几个值得装的插件
虽然主题是"原生功能",但有几个插件确实显著提升:
- GitLens:行 blame / file history / interactive rebase
- Error Lens:errors / warnings inline 显示
- REST Client:写
.http文件直接调 API - Code Spell Checker:拼写检查(注释 / 字符串)
- Better Comments:
// TODO:// FIXME:颜色区分
不是 30+ 个的"插件汤",5 个就够了。
性能 tip
{
"files.watcherExclude": {
"**/node_modules/**": true,
"**/dist/**": true
},
"search.followSymlinks": false,
"telemetry.telemetryLevel": "off"
}
大项目(monorepo / 10万+ 文件)watcher 吃 CPU,excluded 加快。
远程开发:Remote-SSH
服务器代码不想 mount / sync 到本地?
Remote-SSH: Connect to Host → server.example.com
VSCode 在远程跑 server 端,本地 UI 显示,编辑 / debugger / terminal
都像在本地。开发服务器 / 大型 GPU 机器场景神器。
效果
教会团队新人这 12 个:
- 多光标改名场景 -80% find/replace 使用
- "我代码格式不对了" 类 PR 评论消失(save 自动 format)
- 不再"打开第二个窗口跑 terminal"(内置 terminal 够用)
- workspace settings 进 git 让团队体验一致
踩过的坑
-
settings.json 全局 vs workspace 冲突:workspace > user > default。
优先级搞清楚。 -
format on save 改了你不想改的:prettier 把字符串单引号改成双
引号之类。.editorconfig+.prettierrc配项目偏好。 -
多个 formatter for same language:
editor.defaultFormatter强
指定,否则每次问你用哪个。 -
Ctrl+Shift+P 命令找不到:扩展没装就没那个命令。装对应 extension
后 reload window。 -
远程 SSH 在 ARM mac 连 x86 server:第一次连慢(下 server 端
binary)。挂代理设remote.SSH.useExecServer: false减少 hop。
登录后参与评论。