编辑器配置

Aider 允许您配置首选的文本编辑器以配合 /editor 命令使用。该编辑器必须能够在”阻塞模式”下运行,这意味着命令行会等待您关闭编辑器后才继续执行。

使用 --editor 参数

您可以通过 --editor 开关或在 aider 的 YAML 配置文件 中使用 editor: 来指定文本编辑器。

环境变量

Aider 会按顺序检查以下环境变量来确定使用哪个编辑器:

  1. AIDER_EDITOR
  2. VISUAL
  3. EDITOR

默认行为

如果未配置编辑器,aider 将使用以下平台特定的默认值:

  • Windows: notepad
  • macOS: vim
  • Linux/Unix: vi

使用自定义编辑器

您可以在 shell 的配置文件(如 .bashrc.zshrc)中设置首选编辑器:

export AIDER_EDITOR=vim

各平台常用编辑器配置

macOS

  1. vim
    export AIDER_EDITOR=vim
    
  2. Emacs
    export AIDER_EDITOR=emacs
    
  3. VSCode
    export AIDER_EDITOR="code --wait"
    
  4. Sublime Text
    export AIDER_EDITOR="subl --wait"
    
  5. BBEdit
    export AIDER_EDITOR="bbedit --wait"
    

Linux

  1. vim
    export AIDER_EDITOR=vim
    
  2. Emacs
    export AIDER_EDITOR=emacs
    
  3. nano
    export AIDER_EDITOR=nano
    
  4. VSCode
    export AIDER_EDITOR="code --wait"
    
  5. Sublime Text
    export AIDER_EDITOR="subl --wait"
    

Windows

  1. 记事本
    set AIDER_EDITOR=notepad
    
  2. VSCode
    set AIDER_EDITOR="code --wait"
    
  3. Notepad++
    set AIDER_EDITOR="notepad++ -multiInst -notabbar -nosession -noPlugin -waitForClose"
    

编辑器命令参数

某些编辑器需要特定的命令行参数才能在阻塞模式下运行。通常使用 --wait 标志(或等效参数)使编辑器阻塞直到文件关闭。

故障排查

如果您遇到编辑器不阻塞(立即返回提示符)的问题,请确认:

  1. 您的编辑器支持阻塞模式
  2. 您已包含阻塞模式所需的命令行参数
  3. 如果编辑器命令包含空格或特殊字符,请正确使用引号,例如:
    export AIDER_EDITOR="code --wait"
    

目录