编辑器配置
Aider 允许您配置首选的文本编辑器以配合 /editor
命令使用。该编辑器必须能够在”阻塞模式”下运行,这意味着命令行会等待您关闭编辑器后才继续执行。
使用 --editor
参数
您可以通过 --editor
开关或在 aider 的 YAML 配置文件 中使用 editor:
来指定文本编辑器。
环境变量
Aider 会按顺序检查以下环境变量来确定使用哪个编辑器:
AIDER_EDITOR
VISUAL
EDITOR
默认行为
如果未配置编辑器,aider 将使用以下平台特定的默认值:
- Windows:
notepad
- macOS:
vim
- Linux/Unix:
vi
使用自定义编辑器
您可以在 shell 的配置文件(如 .bashrc
、.zshrc
)中设置首选编辑器:
export AIDER_EDITOR=vim
各平台常用编辑器配置
macOS
- vim
export AIDER_EDITOR=vim
- Emacs
export AIDER_EDITOR=emacs
- VSCode
export AIDER_EDITOR="code --wait"
- Sublime Text
export AIDER_EDITOR="subl --wait"
- BBEdit
export AIDER_EDITOR="bbedit --wait"
Linux
- vim
export AIDER_EDITOR=vim
- Emacs
export AIDER_EDITOR=emacs
- nano
export AIDER_EDITOR=nano
- VSCode
export AIDER_EDITOR="code --wait"
- Sublime Text
export AIDER_EDITOR="subl --wait"
Windows
- 记事本
set AIDER_EDITOR=notepad
- VSCode
set AIDER_EDITOR="code --wait"
- Notepad++
set AIDER_EDITOR="notepad++ -multiInst -notabbar -nosession -noPlugin -waitForClose"
编辑器命令参数
某些编辑器需要特定的命令行参数才能在阻塞模式下运行。通常使用 --wait
标志(或等效参数)使编辑器阻塞直到文件关闭。
故障排查
如果您遇到编辑器不阻塞(立即返回提示符)的问题,请确认:
- 您的编辑器支持阻塞模式
- 您已包含阻塞模式所需的命令行参数
- 如果编辑器命令包含空格或特殊字符,请正确使用引号,例如:
export AIDER_EDITOR="code --wait"