第7章 Zed 内置终端功能详解
Zed 内置了终端模拟器,支持多终端实例、自定义 Shell,并与编辑器深度集成。
打开终端
| 操作 | macOS | Linux/Windows |
|---|---|---|
| 切换终端面板 | Ctrl+` |
Ctrl+` |
| 新建终端 | Ctrl+~ |
Ctrl+~ |
| 在中央区域打开终端 | 命令面板 | 命令面板 |
你也可以通过命令面板使用 {#action terminal_panel::Toggle} 或 {#action workspace::NewTerminal} 来打开终端。
终端面板与中央终端
终端可以打开在两个位置:
- 终端面板 — 停靠在工作区的底部(默认)、左侧或右侧。使用
Ctrl+`切换。 - 中央面板 — 作为普通标签页打开,与文件并列。在命令面板中使用 {#action workspace::NewCenterTerminal}。
多终端操作
在终端面板处于聚焦状态时,按 Cmd+N (macOS) 或 Ctrl+N (Linux/Windows) 创建额外终端。每个终端都会显示为面板中的一个标签。
使用 Cmd+D (macOS) 或 Ctrl+Shift+5 (Linux/Windows) 水平分割终端。
配置 Shell
默认情况下,Zed 使用系统默认 Shell(Unix 系统下取自 /etc/passwd)。要使用其他 Shell:
{
"terminal": {
"shell": {
"program": "/bin/zsh"
}
}
}
要为 Shell 传递参数:
{
"terminal": {
"shell": {
"with_arguments": {
"program": "/bin/bash",
"args": ["--login"]
}
}
}
}
工作目录
控制新终端的启动位置:
| 值 | 行为 |
|---|---|
"current_file_directory" |
使用当前文件所在的目录,若不存在则回退到项目目录,最后回退到工作区中的第一个项目 |
"current_project_directory" |
使用当前文件所在的项目目录(默认) |
"first_project_directory" |
使用工作区中的第一个项目目录 |
"always_home" |
始终从用户主目录启动 |
{ "always": { "directory": "~/projects" } } |
始终从指定目录启动 |
{
"terminal": {
"working_directory": "first_project_directory"
}
}
环境变量
可以为所有终端会话添加环境变量:
{
"terminal": {
"env": {
"EDITOR": "zed --wait",
"MY_VAR": "value"
}
}
}
提示:在同一个变量中可以用
:分隔多个值,例如:"PATH": "/custom/path:$PATH"
Python 虚拟环境检测
打开终端时,Zed 可以自动激活 Python 虚拟环境。默认会搜索 .env、env、.venv 和 venv 目录:
{
"terminal": {
"detect_venv": {
"on": {
"directories": [".venv", "venv"],
"activate_script": "default"
}
}
}
}
activate_script 选项支持 "default"、"csh"、"fish" 和 "nushell"。
如需禁用虚拟环境检测:
{
"terminal": {
"detect_venv": "off"
}
}
字体与外观
终端可以使用与编辑器不同的字体:
{
"terminal": {
"font_family": "JetBrains Mono",
"font_size": 14,
"font_features": {
"calt": false
},
"line_height": "comfortable"
}
}
行高选项:
"comfortable"— 1.618 倍比例,阅读体验好(默认)"standard"— 1.3 倍率,适合使用制表符的 TUI 应用{ "custom": 1.5 }— 自定义倍率
光标
配置光标外观:
{
"terminal": {
"cursor_shape": "bar",
"blinking": "on"
}
}
光标形状:"block"、"bar"、"underline"、"hollow"
闪烁选项:"off"、"terminal_controlled"(默认)、"on"
最小对比度
Zed 会调整终端颜色以保证可读性。默认值 45 确保文本清晰可见。设为 0 可禁用对比度调整,直接使用主题原始颜色:
{
"terminal": {
"minimum_contrast": 0
}
}
滚动
使用以下快捷键浏览终端历史记录:
| 操作 | macOS | Linux/Windows |
|---|---|---|
| 向上翻页 | Shift+PageUp 或 Cmd+Up |
Shift+PageUp |
| 向下翻页 | Shift+PageDown 或 Cmd+Down |
Shift+PageDown |
| 向上滚一行 | Shift+Up |
Shift+Up |
| 向下滚一行 | Shift+Down |
Shift+Down |
| 滚到顶部 | Shift+Home 或 Cmd+Home |
Shift+Home |
| 滚到底部 | Shift+End 或 Cmd+End |
Shift+End |
通过以下方式调整滚动速度:
{
"terminal": {
"scroll_multiplier": 3.0
}
}
复制与粘贴
| 操作 | macOS | Linux/Windows |
|---|---|---|
| 复制 | Cmd+C |
Ctrl+Shift+C |
| 粘贴 | Cmd+V |
Ctrl+Shift+V |
选择即复制
自动将选中文本复制到剪贴板:
{
"terminal": {
"copy_on_select": true
}
}
复制后保留选中状态
默认情况下,复制后文本仍保持选中状态。若要清除选中状态,请设置:
{
"terminal": {
"keep_selection_on_copy": false
}
}
搜索
使用 Cmd+F(macOS)或 Ctrl+Shift+F(Linux/Windows)搜索终端内容。这将打开与编辑器相同的搜索栏。
Vi 模式
通过 Ctrl+Shift+Space 在终端中切换 vi 风格导航。这允许你使用 vi 键位绑定来导航和选择文本。
清屏
清除终端屏幕:
- macOS:
Cmd+K - Linux/Windows:
Ctrl+Shift+L
Option 键作为 Meta 键(macOS)
对于 Emacs 用户或需要 Meta 键组合的应用程序,可启用 Option 键作为 Meta 键:
{
"terminal": {
"option_as_meta": true
}
}
此设置将 Option 键重新解释为 Meta 键,使 Alt+X 等序列能正常工作。
备用滚动模式
启用后,在 vim 或 less 等应用中,鼠标滚轮事件将转换为方向键按下:
{
"terminal": {
"alternate_scroll": "on"
}
}
路径超链接
Zed 会检测终端输出中的文件路径并使其可点击。Cmd+Click(macOS)或 Ctrl+Click(Linux/Windows)可在 Zed 中打开该文件,若检测到行号,则跳转至该行。
识别的常见格式包括:
src/main.rs:42— 打开第 42 行src/main.rs:42:10— 打开第 42 行、第 10 列File "script.py", line 10— Python 堆栈跟踪
默认情况下,即使运行中的应用启用了鼠标报告(例如 mouse=a 模式的 vim 或 htop),Cmd+Click/Ctrl+Click 也会打开链接。若希望将点击事件转发给应用而非打开链接,请禁用 open_links_in_mouse_mode;此时仍可通过 Shift+Cmd+Click(Shift+Ctrl+Click)打开链接:
{
"terminal": {
"open_links_in_mouse_mode": false
}
}
面板配置
停靠位置
{
"terminal": {
"dock": "bottom"
}
}
可选值:"bottom"(默认)、"left"、"right"
默认尺寸
{
"terminal": {
"default_width": 640,
"default_height": 320
}
}
终端按钮
隐藏状态栏中的终端按钮:
{
"terminal": {
"button": false
}
}
工具栏
在面包屑工具栏中显示终端标题:
{
"terminal": {
"toolbar": {
"breadcrumbs": true
}
}
}
标题可以通过 shell 使用转义序列 \e]2;Title\007 来设置。
与任务集成
终端与 Zed 的任务系统集成。运行任务时会直接在终端中执行。在终端中重新运行上一个任务的快捷键:
- macOS:
Cmd+Alt+R - Linux/Windows:
Ctrl+Shift+R或Alt+T
AI 辅助
使用Inline Assistant 获取终端命令相关的帮助:
- macOS:
Ctrl+Enter - Linux/Windows:
Ctrl+Enter或Ctrl+I
这会打开 Inline Assistant,帮你解释报错、推荐命令或排查问题。Agent Panel 中的 AI agent 也可以在自己的工作流程中执行终端命令。
发送文本和按键
如需深度自定义快捷键,可以向终端发送原始文本或按键:
{
"context": "Terminal",
"bindings": {
"alt-left": ["terminal::SendText", "\u001bb"],
"ctrl-c": ["terminal::SendKeystroke", "ctrl-c"]
}
}
所有终端设置
如需查看完整的终端设置列表,请参阅所有设置文档中的“终端”部分。