1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
|
---
title: TUI
description: 使用 OpenCode 终端用户界面。
---
import { Tabs, TabItem } from "@astrojs/starlight/components"
OpenCode 提供了一个交互式终端界面(TUI),用于配合 LLM 处理您的项目。
运行 OpenCode 即可启动当前目录的 TUI。
```bash
opencode
```
或者您可以为指定的工作目录启动它。
```bash
opencode /path/to/project
```
进入 TUI 后,您可以输入消息进行提示。
```text
Give me a quick summary of the codebase.
```
---
## 文件引用
您可以使用 `@` 在消息中引用文件。这会在当前工作目录中进行模糊文件搜索。
:::tip
您还可以使用 `@` 来引用消息中的文件。
:::
```text "@packages/functions/src/api/index.ts"
How is auth handled in @packages/functions/src/api/index.ts?
```
文件的内容会自动添加到对话中。
---
## Bash 命令
以 `!` 开头的消息会作为 shell 命令执行。
```bash frame="none"
!ls -la
```
命令的输出会作为工具结果添加到对话中。
---
## 命令
使用 OpenCode TUI 时,您可以输入 `/` 后跟命令名称来快速执行操作。例如:
```bash frame="none"
/help
```
大多数命令还支持以 `ctrl+x` 作为前导键的快捷键,其中 `ctrl+x` 是默认前导键。[了解更多](/docs/keybinds)。
以下是所有可用的斜杠命令:
---
### connect
将提供商添加到 OpenCode。允许您从可用的提供商中选择并添加其 API 密钥。
```bash frame="none"
/connect
```
---
### compact
压缩当前会话。_别名_:`/summarize`
```bash frame="none"
/compact
```
**快捷键:** `ctrl+x c`
---
### details
切换工具执行详情的显示。
```bash frame="none"
/details
```
**快捷键:** `ctrl+x d`
---
### editor
打开外部编辑器来编写消息。使用 `EDITOR` 环境变量中设置的编辑器。[了解更多](#editor-setup)。
```bash frame="none"
/editor
```
**快捷键:** `ctrl+x e`
---
### exit
退出 OpenCode。_别名_:`/quit`、`/q`
```bash frame="none"
/exit
```
**快捷键:** `ctrl+x q`
---
### export
将当前对话导出为 Markdown 并在默认编辑器中打开。使用 `EDITOR` 环境变量中设置的编辑器。[了解更多](#editor-setup)。
```bash frame="none"
/export
```
**快捷键:** `ctrl+x x`
---
### help
显示帮助对话框。
```bash frame="none"
/help
```
**快捷键:** `ctrl+x h`
---
### init
创建或更新 `AGENTS.md` 文件。[了解更多](/docs/rules)。
```bash frame="none"
/init
```
**快捷键:** `ctrl+x i`
---
### models
列出可用模型。
```bash frame="none"
/models
```
**快捷键:** `ctrl+x m`
---
### new
开始新的会话。_别名_:`/clear`
```bash frame="none"
/new
```
**快捷键:** `ctrl+x n`
---
### redo
重做之前撤销的消息。仅在使用 `/undo` 后可用。
:::tip
所有文件更改也会被恢复。
:::
在内部,这使用 Git 来管理文件更改。因此您的项目**需要是一个 Git 仓库**。
```bash frame="none"
/redo
```
**快捷键:** `ctrl+x r`
---
### sessions
列出会话并在会话之间切换。_别名_:`/resume`、`/continue`
```bash frame="none"
/sessions
```
**快捷键:** `ctrl+x l`
---
### share
分享当前会话。[了解更多](/docs/share)。
```bash frame="none"
/share
```
**快捷键:** `ctrl+x s`
---
### themes
列出可用主题。
```bash frame="none"
/themes
```
**快捷键:** `ctrl+x t`
---
### thinking
切换对话中思考/推理块的可见性。启用后,您可以看到支持扩展思考的模型的推理过程。
:::note
此命令仅控制思考块是否**显示** — 它不会启用或禁用模型的推理能力。要切换实际的推理能力,请使用 `ctrl+t` 循环切换模型变体。
:::
```bash frame="none"
/thinking
```
---
### undo
撤销对话中的最后一条消息。移除最近的用户消息、所有后续响应以及所有文件更改。
:::tip
所做的任何文件更改也会被还原。
:::
在内部,这使用 Git 来管理文件更改。因此您的项目**需要是一个 Git 仓库**。
```bash frame="none"
/undo
```
**快捷键:** `ctrl+x u`
---
### unshare
取消分享当前会话。[了解更多](/docs/share#un-sharing)。
```bash frame="none"
/unshare
```
---
## 编辑器设置
`/editor` 和 `/export` 命令都使用 `EDITOR` 环境变量中指定的编辑器。
<Tabs>
<TabItem label="Linux/macOS">
```bash
# Example for nano or vim
export EDITOR=nano
export EDITOR=vim
# For GUI editors, VS Code, Cursor, VSCodium, Windsurf, Zed, etc.
# include --wait
export EDITOR="code --wait"
```
要使其永久生效,请将其添加到您的 shell 配置文件中;
`~/.bashrc`、`~/.zshrc` 等。
</TabItem>
<TabItem label="Windows (CMD)">
```bash
set EDITOR=notepad
# For GUI editors, VS Code, Cursor, VSCodium, Windsurf, Zed, etc.
# include --wait
set EDITOR=code --wait
```
要使其永久生效,请使用**系统属性** > **环境变量**。
</TabItem>
<TabItem label="Windows (PowerShell)">
```powershell
$env:EDITOR = "notepad"
# For GUI editors, VS Code, Cursor, VSCodium, Windsurf, Zed, etc.
# include --wait
$env:EDITOR = "code --wait"
```
要使其永久生效,请将其添加到您的 PowerShell 配置文件中。
</TabItem>
</Tabs>
常用的编辑器选项包括:
- `code` - Visual Studio Code
- `cursor` - Cursor
- `windsurf` - Windsurf
- `nvim` - Neovim 编辑器
- `vim` - Vim 编辑器
- `nano` - Nano 编辑器
- `notepad` - Notepad(Windows 记事本)
- `subl` - Sublime Text
:::note
某些编辑器(如 VS Code)需要以 `--wait` 标志启动。
:::
某些编辑器需要命令行参数才能以阻塞模式运行。`--wait` 标志使编辑器进程阻塞直到关闭。
---
## 配置
您可以通过 OpenCode 配置文件自定义 TUI 行为。
```json title="opencode.json"
{
"$schema": "https://opencode.ai/config.json",
"tui": {
"scroll_speed": 3,
"scroll_acceleration": {
"enabled": true
}
}
}
```
### 选项
- `scroll_acceleration` - 启用 macOS 风格的滚动加速,实现平滑、自然的滚动体验。启用后,快速滚动时速度会增加,慢速移动时保持精确。**此设置优先于 `scroll_speed`,启用时会覆盖它。**
- `scroll_speed` - 控制使用滚动命令时 TUI 的滚动速度(最小值:`1`)。默认为 `3`。**注意:如果 `scroll_acceleration.enabled` 设置为 `true`,则此设置会被忽略。**
---
## 自定义
您可以使用命令面板(`ctrl+x h` 或 `/help`)自定义 TUI 视图的各个方面。这些设置在重启后仍会保留。
---
#### 用户名显示
切换您的用户名是否显示在聊天消息中。通过以下方式访问:
- 命令面板:搜索 "username" 或 "hide username"
- 该设置会自动保存,并在各个 TUI 会话中保持记忆
|